GCC Code Coverage Report


Directory: ./
File: extra/libkmip/libkmip/src/kmip.c
Date: 2022-11-26 14:12:44
Exec Total Coverage
Lines: 0 7936 0.0%
Branches: 0 5423 0.0%

Line Branch Exec Source
1 /* Copyright (c) 2018 The Johns Hopkins University/Applied Physics Laboratory
2 * All Rights Reserved.
3 *
4 * This file is dual licensed under the terms of the Apache 2.0 License and
5 * the BSD 3-Clause License. See the LICENSE file in the root of this
6 * repository for more information.
7 */
8
9 #include <limits.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <time.h>
14
15 #include "kmip.h"
16 #include "kmip_memset.h"
17 #include "kmip_locate.h"
18
19
20 /*
21 Miscellaneous Utilities
22 */
23
24 size_t
25 kmip_strnlen_s(const char *str, size_t strsz)
26 {
27 if(str == NULL)
28 {
29 return(0);
30 }
31
32 size_t length = 0;
33 for(const char *i = str; *i != 0; i++)
34 {
35 length++;
36 if(length >= strsz)
37 {
38 return(strsz);
39 }
40 }
41 return(length);
42 }
43
44 LinkedListItem *
45 kmip_linked_list_pop(LinkedList *list)
46 {
47 if(list == NULL)
48 {
49 return(NULL);
50 }
51
52 LinkedListItem *popped = list->head;
53
54 if(popped != NULL)
55 {
56 list->head = popped->next;
57 popped->next = NULL;
58 popped->prev = NULL;
59
60 if(list->head != NULL)
61 {
62 list->head->prev = NULL;
63 }
64
65 if(popped == list->tail)
66 {
67 list->tail = NULL;
68 }
69
70 if(list->size > 0)
71 {
72 list->size -= 1;
73 }
74 }
75 else
76 {
77 if(list->size != 0)
78 {
79 list->size = 0;
80 }
81 }
82
83 return(popped);
84 }
85
86 void
87 kmip_linked_list_push(LinkedList *list, LinkedListItem *item)
88 {
89 if(list != NULL && item != NULL)
90 {
91 LinkedListItem *head = list->head;
92 list->head = item;
93 item->next = head;
94 item->prev = NULL;
95 list->size += 1;
96
97 if(head != NULL)
98 {
99 head->prev = item;
100 }
101
102 if(list->tail == NULL)
103 {
104 list->tail = list->head;
105 }
106 }
107 }
108
109 void
110 kmip_linked_list_enqueue(LinkedList *list, LinkedListItem *item)
111 {
112 if(list != NULL && item != NULL)
113 {
114 LinkedListItem *tail = list->tail;
115 list->tail = item;
116 item->next = NULL;
117 item->prev = tail;
118 list->size += 1;
119
120 if(tail != NULL)
121 {
122 tail->next = item;
123 }
124
125 if(list->head == NULL)
126 {
127 list->head = list->tail;
128 }
129 }
130 }
131
132 /*
133 Memory Handlers
134 */
135
136 void *
137 kmip_calloc(void *state, size_t num, size_t size)
138 {
139 (void)state;
140 return(calloc(num, size));
141 }
142
143 void *
144 kmip_realloc(void *state, void *ptr, size_t size)
145 {
146 (void)state;
147 return(realloc(ptr, size));
148 }
149
150 void
151 kmip_free(void *state, void *ptr)
152 {
153 (void)state;
154 free(ptr);
155 return;
156 }
157
158 /* TODO (ph) Consider replacing this with memcpy_s, ala memset_s. */
159 void *
160 kmip_memcpy(void *state, void *destination, const void *source, size_t size)
161 {
162 (void)state;
163 return(memcpy(destination, source, size));
164 }
165
166 /*
167 Enumeration Utilities
168 */
169
170 static const char *kmip_attribute_names[26] = {
171 "Attestation Type",
172 "BatchErrorContinuation Option",
173 "BlockCipher Mode",
174 "Credential Type",
175 "Cryptographic Algorithm",
176 "Cryptographic Usage Mask",
177 "DigitalSignature Algorithm",
178 "Encoding Option",
179 "Hashing Algorithm",
180 "Key Compression Type",
181 "Key Format Type",
182 "Key Role Type",
183 "Key Wrap Type",
184 "Mask Generator",
185 "Name Type",
186 "Object Type",
187 "Operation",
188 "Padding Method",
189 "Protection Storage Mask",
190 "Result Reason",
191 "Result Status",
192 "State",
193 "Tag", /*?*/
194 "Type", /*?*/
195 "Wrapping Method",
196 "Unknown" /* Catch all for unsupported enumerations */
197 };
198
199 int
200 kmip_get_enum_string_index(enum tag t)
201 {
202 switch(t)
203 {
204 case KMIP_TAG_ATTESTATION_TYPE:
205 return(0);
206 break;
207
208 case KMIP_TAG_BATCH_ERROR_CONTINUATION_OPTION:
209 return(1);
210 break;
211
212 case KMIP_TAG_BLOCK_CIPHER_MODE:
213 return(2);
214 break;
215
216 case KMIP_TAG_CREDENTIAL_TYPE:
217 return(3);
218 break;
219
220 case KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM:
221 return(4);
222 break;
223
224 case KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK:
225 return(5);
226 break;
227
228 case KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM:
229 return(6);
230 break;
231
232 case KMIP_TAG_ENCODING_OPTION:
233 return(7);
234 break;
235
236 case KMIP_TAG_HASHING_ALGORITHM:
237 return(8);
238 break;
239
240 case KMIP_TAG_KEY_COMPRESSION_TYPE:
241 return(9);
242 break;
243
244 case KMIP_TAG_KEY_FORMAT_TYPE:
245 return(10);
246 break;
247
248 case KMIP_TAG_KEY_ROLE_TYPE:
249 return(11);
250 break;
251
252 case KMIP_TAG_KEY_WRAP_TYPE:
253 return(12);
254 break;
255
256 case KMIP_TAG_MASK_GENERATOR:
257 return(13);
258 break;
259
260 case KMIP_TAG_NAME_TYPE:
261 return(14);
262 break;
263
264 case KMIP_TAG_OBJECT_TYPE:
265 return(15);
266 break;
267
268 case KMIP_TAG_OPERATION:
269 return(16);
270 break;
271
272 case KMIP_TAG_PADDING_METHOD:
273 return(17);
274 break;
275
276 case KMIP_TAG_PROTECTION_STORAGE_MASK:
277 return(18);
278 break;
279
280 case KMIP_TAG_RESULT_REASON:
281 return(19);
282 break;
283
284 case KMIP_TAG_RESULT_STATUS:
285 return(20);
286 break;
287
288 case KMIP_TAG_STATE:
289 return(21);
290 break;
291
292 case KMIP_TAG_TAG:
293 return(22);
294 break;
295
296 case KMIP_TAG_TYPE:
297 return(23);
298 break;
299
300 case KMIP_TAG_WRAPPING_METHOD:
301 return(24);
302 break;
303
304 default:
305 return(25);
306 break;
307 };
308 }
309
310 int
311 kmip_check_enum_value(enum kmip_version version, enum tag t, int value)
312 {
313 switch(t)
314 {
315 case KMIP_TAG_ATTESTATION_TYPE:
316 switch(value)
317 {
318 case KMIP_ATTEST_TPM_QUOTE:
319 case KMIP_ATTEST_TCG_INTEGRITY_REPORT:
320 case KMIP_ATTEST_SAML_ASSERTION:
321 if(version >= KMIP_1_2)
322 return(KMIP_OK);
323 else
324 return(KMIP_INVALID_FOR_VERSION);
325 break;
326
327 default:
328 return(KMIP_ENUM_MISMATCH);
329 break;
330 };
331 break;
332
333 case KMIP_TAG_BATCH_ERROR_CONTINUATION_OPTION:
334 switch(value)
335 {
336 case KMIP_BATCH_CONTINUE:
337 case KMIP_BATCH_STOP:
338 case KMIP_BATCH_UNDO:
339 return(KMIP_OK);
340 break;
341
342 default:
343 return(KMIP_ENUM_MISMATCH);
344 break;
345 };
346 break;
347
348 case KMIP_TAG_BLOCK_CIPHER_MODE:
349 switch(value)
350 {
351 case KMIP_BLOCK_CBC:
352 case KMIP_BLOCK_ECB:
353 case KMIP_BLOCK_PCBC:
354 case KMIP_BLOCK_CFB:
355 case KMIP_BLOCK_OFB:
356 case KMIP_BLOCK_CTR:
357 case KMIP_BLOCK_CMAC:
358 case KMIP_BLOCK_CCM:
359 case KMIP_BLOCK_GCM:
360 case KMIP_BLOCK_CBC_MAC:
361 case KMIP_BLOCK_XTS:
362 case KMIP_BLOCK_AES_KEY_WRAP_PADDING:
363 case KMIP_BLOCK_NIST_KEY_WRAP:
364 case KMIP_BLOCK_X9102_AESKW:
365 case KMIP_BLOCK_X9102_TDKW:
366 case KMIP_BLOCK_X9102_AKW1:
367 case KMIP_BLOCK_X9102_AKW2:
368 return(KMIP_OK);
369 break;
370
371 case KMIP_BLOCK_AEAD:
372 if(version >= KMIP_1_4)
373 return(KMIP_OK);
374 else
375 return(KMIP_INVALID_FOR_VERSION);
376 break;
377
378 default:
379 return(KMIP_ENUM_MISMATCH);
380 break;
381 };
382 break;
383
384 case KMIP_TAG_CREDENTIAL_TYPE:
385 switch(value)
386 {
387 case KMIP_CRED_USERNAME_AND_PASSWORD:
388 return(KMIP_OK);
389 break;
390
391 case KMIP_CRED_DEVICE:
392 if(version >= KMIP_1_1)
393 return(KMIP_OK);
394 else
395 return(KMIP_INVALID_FOR_VERSION);
396 break;
397
398 case KMIP_CRED_ATTESTATION:
399 if(version >= KMIP_1_2)
400 return(KMIP_OK);
401 else
402 return(KMIP_INVALID_FOR_VERSION);
403 break;
404
405 /* KMIP 2.0 */
406 case KMIP_CRED_ONE_TIME_PASSWORD:
407 case KMIP_CRED_HASHED_PASSWORD:
408 case KMIP_CRED_TICKET:
409 if(version >= KMIP_2_0)
410 return(KMIP_OK);
411 else
412 return(KMIP_INVALID_FOR_VERSION);
413 break;
414
415 default:
416 return(KMIP_ENUM_MISMATCH);
417 break;
418 };
419 break;
420
421 case KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM:
422 switch(value)
423 {
424 case KMIP_CRYPTOALG_DES:
425 case KMIP_CRYPTOALG_TRIPLE_DES:
426 case KMIP_CRYPTOALG_AES:
427 case KMIP_CRYPTOALG_RSA:
428 case KMIP_CRYPTOALG_DSA:
429 case KMIP_CRYPTOALG_ECDSA:
430 case KMIP_CRYPTOALG_HMAC_SHA1:
431 case KMIP_CRYPTOALG_HMAC_SHA224:
432 case KMIP_CRYPTOALG_HMAC_SHA256:
433 case KMIP_CRYPTOALG_HMAC_SHA384:
434 case KMIP_CRYPTOALG_HMAC_SHA512:
435 case KMIP_CRYPTOALG_HMAC_MD5:
436 case KMIP_CRYPTOALG_DH:
437 case KMIP_CRYPTOALG_ECDH:
438 case KMIP_CRYPTOALG_ECMQV:
439 case KMIP_CRYPTOALG_BLOWFISH:
440 case KMIP_CRYPTOALG_CAMELLIA:
441 case KMIP_CRYPTOALG_CAST5:
442 case KMIP_CRYPTOALG_IDEA:
443 case KMIP_CRYPTOALG_MARS:
444 case KMIP_CRYPTOALG_RC2:
445 case KMIP_CRYPTOALG_RC4:
446 case KMIP_CRYPTOALG_RC5:
447 case KMIP_CRYPTOALG_SKIPJACK:
448 case KMIP_CRYPTOALG_TWOFISH:
449 return(KMIP_OK);
450 break;
451
452 case KMIP_CRYPTOALG_EC:
453 if(version >= KMIP_1_2)
454 return(KMIP_OK);
455 else
456 return(KMIP_INVALID_FOR_VERSION);
457 break;
458
459 case KMIP_CRYPTOALG_ONE_TIME_PAD:
460 if(version >= KMIP_1_3)
461 return(KMIP_OK);
462 else
463 return(KMIP_INVALID_FOR_VERSION);
464 break;
465
466 case KMIP_CRYPTOALG_CHACHA20:
467 case KMIP_CRYPTOALG_POLY1305:
468 case KMIP_CRYPTOALG_CHACHA20_POLY1305:
469 case KMIP_CRYPTOALG_SHA3_224:
470 case KMIP_CRYPTOALG_SHA3_256:
471 case KMIP_CRYPTOALG_SHA3_384:
472 case KMIP_CRYPTOALG_SHA3_512:
473 case KMIP_CRYPTOALG_HMAC_SHA3_224:
474 case KMIP_CRYPTOALG_HMAC_SHA3_256:
475 case KMIP_CRYPTOALG_HMAC_SHA3_384:
476 case KMIP_CRYPTOALG_HMAC_SHA3_512:
477 case KMIP_CRYPTOALG_SHAKE_128:
478 case KMIP_CRYPTOALG_SHAKE_256:
479 if(version >= KMIP_1_4)
480 return(KMIP_OK);
481 else
482 return(KMIP_INVALID_FOR_VERSION);
483 break;
484
485 /* KMIP 2.0 */
486 case KMIP_CRYPTOALG_ARIA:
487 case KMIP_CRYPTOALG_SEED:
488 case KMIP_CRYPTOALG_SM2:
489 case KMIP_CRYPTOALG_SM3:
490 case KMIP_CRYPTOALG_SM4:
491 case KMIP_CRYPTOALG_GOST_R_34_10_2012:
492 case KMIP_CRYPTOALG_GOST_R_34_11_2012:
493 case KMIP_CRYPTOALG_GOST_R_34_13_2015:
494 case KMIP_CRYPTOALG_GOST_28147_89:
495 case KMIP_CRYPTOALG_XMSS:
496 case KMIP_CRYPTOALG_SPHINCS_256:
497 case KMIP_CRYPTOALG_MCELIECE:
498 case KMIP_CRYPTOALG_MCELIECE_6960119:
499 case KMIP_CRYPTOALG_MCELIECE_8192128:
500 case KMIP_CRYPTOALG_ED25519:
501 case KMIP_CRYPTOALG_ED448:
502 if(version >= KMIP_2_0)
503 return(KMIP_OK);
504 else
505 return(KMIP_INVALID_FOR_VERSION);
506 break;
507
508 default:
509 return(KMIP_ENUM_MISMATCH);
510 break;
511 };
512 break;
513
514 case KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK:
515 switch(value)
516 {
517 case KMIP_CRYPTOMASK_SIGN:
518 case KMIP_CRYPTOMASK_VERIFY:
519 case KMIP_CRYPTOMASK_ENCRYPT:
520 case KMIP_CRYPTOMASK_DECRYPT:
521 case KMIP_CRYPTOMASK_WRAP_KEY:
522 case KMIP_CRYPTOMASK_UNWRAP_KEY:
523 case KMIP_CRYPTOMASK_EXPORT:
524 case KMIP_CRYPTOMASK_MAC_GENERATE:
525 case KMIP_CRYPTOMASK_MAC_VERIFY:
526 case KMIP_CRYPTOMASK_DERIVE_KEY:
527 case KMIP_CRYPTOMASK_CONTENT_COMMITMENT:
528 case KMIP_CRYPTOMASK_KEY_AGREEMENT:
529 case KMIP_CRYPTOMASK_CERTIFICATE_SIGN:
530 case KMIP_CRYPTOMASK_CRL_SIGN:
531 case KMIP_CRYPTOMASK_GENERATE_CRYPTOGRAM:
532 case KMIP_CRYPTOMASK_VALIDATE_CRYPTOGRAM:
533 case KMIP_CRYPTOMASK_TRANSLATE_ENCRYPT:
534 case KMIP_CRYPTOMASK_TRANSLATE_DECRYPT:
535 case KMIP_CRYPTOMASK_TRANSLATE_WRAP:
536 case KMIP_CRYPTOMASK_TRANSLATE_UNWRAP:
537 return(KMIP_OK);
538 break;
539
540 /* KMIP 2.0 */
541 case KMIP_CRYPTOMASK_AUTHENTICATE:
542 case KMIP_CRYPTOMASK_UNRESTRICTED:
543 case KMIP_CRYPTOMASK_FPE_ENCRYPT:
544 case KMIP_CRYPTOMASK_FPE_DECRYPT:
545 if(version >= KMIP_2_0)
546 return(KMIP_OK);
547 else
548 return(KMIP_INVALID_FOR_VERSION);
549 break;
550
551 default:
552 return(KMIP_ENUM_MISMATCH);
553 break;
554 };
555 break;
556
557 case KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM:
558 switch(value)
559 {
560 case KMIP_DIGITAL_MD2_WITH_RSA:
561 case KMIP_DIGITAL_MD5_WITH_RSA:
562 case KMIP_DIGITAL_SHA1_WITH_RSA:
563 case KMIP_DIGITAL_SHA224_WITH_RSA:
564 case KMIP_DIGITAL_SHA256_WITH_RSA:
565 case KMIP_DIGITAL_SHA384_WITH_RSA:
566 case KMIP_DIGITAL_SHA512_WITH_RSA:
567 case KMIP_DIGITAL_RSASSA_PSS:
568 case KMIP_DIGITAL_DSA_WITH_SHA1:
569 case KMIP_DIGITAL_DSA_WITH_SHA224:
570 case KMIP_DIGITAL_DSA_WITH_SHA256:
571 case KMIP_DIGITAL_ECDSA_WITH_SHA1:
572 case KMIP_DIGITAL_ECDSA_WITH_SHA224:
573 case KMIP_DIGITAL_ECDSA_WITH_SHA256:
574 case KMIP_DIGITAL_ECDSA_WITH_SHA384:
575 case KMIP_DIGITAL_ECDSA_WITH_SHA512:
576 if(version >= KMIP_1_1)
577 return(KMIP_OK);
578 else
579 return(KMIP_INVALID_FOR_VERSION);
580 break;
581
582 case KMIP_DIGITAL_SHA3_256_WITH_RSA:
583 case KMIP_DIGITAL_SHA3_384_WITH_RSA:
584 case KMIP_DIGITAL_SHA3_512_WITH_RSA:
585 if(version >= KMIP_1_4)
586 return(KMIP_OK);
587 else
588 return(KMIP_INVALID_FOR_VERSION);
589 break;
590
591 default:
592 return(KMIP_ENUM_MISMATCH);
593 break;
594 };
595 break;
596
597 case KMIP_TAG_ENCODING_OPTION:
598 switch(value)
599 {
600 case KMIP_ENCODE_NO_ENCODING:
601 case KMIP_ENCODE_TTLV_ENCODING:
602 if(version >= KMIP_1_1)
603 return(KMIP_OK);
604 else
605 return(KMIP_INVALID_FOR_VERSION);
606 break;
607
608 default:
609 return(KMIP_ENUM_MISMATCH);
610 break;
611 };
612 break;
613
614 case KMIP_TAG_HASHING_ALGORITHM:
615 switch(value)
616 {
617 case KMIP_HASH_MD2:
618 case KMIP_HASH_MD4:
619 case KMIP_HASH_MD5:
620 case KMIP_HASH_SHA1:
621 case KMIP_HASH_SHA224:
622 case KMIP_HASH_SHA256:
623 case KMIP_HASH_SHA384:
624 case KMIP_HASH_SHA512:
625 case KMIP_HASH_RIPEMD160:
626 case KMIP_HASH_TIGER:
627 case KMIP_HASH_WHIRLPOOL:
628 return(KMIP_OK);
629 break;
630
631 case KMIP_HASH_SHA512_224:
632 case KMIP_HASH_SHA512_256:
633 if(version >= KMIP_1_2)
634 return(KMIP_OK);
635 else
636 return(KMIP_INVALID_FOR_VERSION);
637 break;
638
639 case KMIP_HASH_SHA3_224:
640 case KMIP_HASH_SHA3_256:
641 case KMIP_HASH_SHA3_384:
642 case KMIP_HASH_SHA3_512:
643 if(version >= KMIP_1_4)
644 return(KMIP_OK);
645 else
646 return(KMIP_INVALID_FOR_VERSION);
647 break;
648
649 default:
650 return(KMIP_ENUM_MISMATCH);
651 break;
652 };
653 break;
654
655 case KMIP_TAG_KEY_COMPRESSION_TYPE:
656 switch(value)
657 {
658 case KMIP_KEYCOMP_EC_PUB_UNCOMPRESSED:
659 case KMIP_KEYCOMP_EC_PUB_X962_COMPRESSED_PRIME:
660 case KMIP_KEYCOMP_EC_PUB_X962_COMPRESSED_CHAR2:
661 case KMIP_KEYCOMP_EC_PUB_X962_HYBRID:
662 return(KMIP_OK);
663 break;
664
665 default:
666 return(KMIP_ENUM_MISMATCH);
667 break;
668 };
669 break;
670
671 case KMIP_TAG_KEY_FORMAT_TYPE:
672 switch(value)
673 {
674 case KMIP_KEYFORMAT_RAW:
675 case KMIP_KEYFORMAT_OPAQUE:
676 case KMIP_KEYFORMAT_PKCS1:
677 case KMIP_KEYFORMAT_PKCS8:
678 case KMIP_KEYFORMAT_X509:
679 case KMIP_KEYFORMAT_EC_PRIVATE_KEY:
680 case KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY:
681 case KMIP_KEYFORMAT_TRANS_DSA_PRIVATE_KEY:
682 case KMIP_KEYFORMAT_TRANS_DSA_PUBLIC_KEY:
683 case KMIP_KEYFORMAT_TRANS_RSA_PRIVATE_KEY:
684 case KMIP_KEYFORMAT_TRANS_RSA_PUBLIC_KEY:
685 case KMIP_KEYFORMAT_TRANS_DH_PRIVATE_KEY:
686 case KMIP_KEYFORMAT_TRANS_DH_PUBLIC_KEY:
687 return(KMIP_OK);
688 break;
689
690 /* The following set is deprecated as of KMIP 1.3 */
691 case KMIP_KEYFORMAT_TRANS_ECDSA_PRIVATE_KEY:
692 case KMIP_KEYFORMAT_TRANS_ECDSA_PUBLIC_KEY:
693 case KMIP_KEYFORMAT_TRANS_ECDH_PRIVATE_KEY:
694 case KMIP_KEYFORMAT_TRANS_ECDH_PUBLIC_KEY:
695 case KMIP_KEYFORMAT_TRANS_ECMQV_PRIVATE_KEY:
696 case KMIP_KEYFORMAT_TRANS_ECMQV_PUBLIC_KEY:
697 /* TODO (ph) What should happen if version >= 1.3? */
698 return(KMIP_OK);
699 break;
700
701 case KMIP_KEYFORMAT_TRANS_EC_PRIVATE_KEY:
702 case KMIP_KEYFORMAT_TRANS_EC_PUBLIC_KEY:
703 if(version >= KMIP_1_3)
704 return(KMIP_OK);
705 else
706 return(KMIP_INVALID_FOR_VERSION);
707 break;
708
709 case KMIP_KEYFORMAT_PKCS12:
710 if(version >= KMIP_1_4)
711 return(KMIP_OK);
712 else
713 return(KMIP_INVALID_FOR_VERSION);
714 break;
715
716 /* KMIP 2.0 */
717 case KMIP_KEYFORMAT_PKCS10:
718 if(version >= KMIP_2_0)
719 return(KMIP_OK);
720 else
721 return(KMIP_INVALID_FOR_VERSION);
722 break;
723
724 default:
725 return(KMIP_ENUM_MISMATCH);
726 break;
727 };
728 break;
729
730 case KMIP_TAG_KEY_ROLE_TYPE:
731 switch(value)
732 {
733 /* KMIP 1.0 */
734 case KMIP_ROLE_BDK:
735 case KMIP_ROLE_CVK:
736 case KMIP_ROLE_DEK:
737 case KMIP_ROLE_MKAC:
738 case KMIP_ROLE_MKSMC:
739 case KMIP_ROLE_MKSMI:
740 case KMIP_ROLE_MKDAC:
741 case KMIP_ROLE_MKDN:
742 case KMIP_ROLE_MKCP:
743 case KMIP_ROLE_MKOTH:
744 case KMIP_ROLE_KEK:
745 case KMIP_ROLE_MAC16609:
746 case KMIP_ROLE_MAC97971:
747 case KMIP_ROLE_MAC97972:
748 case KMIP_ROLE_MAC97973:
749 case KMIP_ROLE_MAC97974:
750 case KMIP_ROLE_MAC97975:
751 case KMIP_ROLE_ZPK:
752 case KMIP_ROLE_PVKIBM:
753 case KMIP_ROLE_PVKPVV:
754 case KMIP_ROLE_PVKOTH:
755 return(KMIP_OK);
756 break;
757
758 /* KMIP 1.4 */
759 case KMIP_ROLE_DUKPT:
760 case KMIP_ROLE_IV:
761 case KMIP_ROLE_TRKBK:
762 if(version >= KMIP_1_4)
763 return(KMIP_OK);
764 else
765 return(KMIP_INVALID_FOR_VERSION);
766 break;
767
768 default:
769 return(KMIP_ENUM_MISMATCH);
770 break;
771 };
772 break;
773
774 case KMIP_TAG_KEY_WRAP_TYPE:
775 switch(value)
776 {
777 /* KMIP 1.4 */
778 case KMIP_WRAPTYPE_NOT_WRAPPED:
779 case KMIP_WRAPTYPE_AS_REGISTERED:
780 if(version >= KMIP_1_4)
781 return(KMIP_OK);
782 else
783 return(KMIP_INVALID_FOR_VERSION);
784 break;
785
786 default:
787 return(KMIP_ENUM_MISMATCH);
788 break;
789 };
790 break;
791
792 case KMIP_TAG_MASK_GENERATOR:
793 switch(value)
794 {
795 /* KMIP 1.4 */
796 case KMIP_MASKGEN_MGF1:
797 if(version >= KMIP_1_4)
798 return(KMIP_OK);
799 else
800 return(KMIP_INVALID_FOR_VERSION);
801 break;
802
803 default:
804 return(KMIP_ENUM_MISMATCH);
805 break;
806 };
807 break;
808
809 case KMIP_TAG_NAME_TYPE:
810 switch(value)
811 {
812 /* KMIP 1.0 */
813 case KMIP_NAME_UNINTERPRETED_TEXT_STRING:
814 case KMIP_NAME_URI:
815 return(KMIP_OK);
816 break;
817
818 default:
819 return(KMIP_ENUM_MISMATCH);
820 break;
821 };
822 break;
823
824 case KMIP_TAG_OBJECT_TYPE:
825 switch(value)
826 {
827 /* KMIP 1.0 */
828 case KMIP_OBJTYPE_CERTIFICATE:
829 case KMIP_OBJTYPE_SYMMETRIC_KEY:
830 case KMIP_OBJTYPE_PUBLIC_KEY:
831 case KMIP_OBJTYPE_PRIVATE_KEY:
832 case KMIP_OBJTYPE_SPLIT_KEY:
833 case KMIP_OBJTYPE_SECRET_DATA:
834 case KMIP_OBJTYPE_OPAQUE_OBJECT:
835 return(KMIP_OK);
836 break;
837
838 /* The following set is deprecated as of KMIP 1.3 */
839 case KMIP_OBJTYPE_TEMPLATE:
840 /* TODO (ph) What should happen if version >= 1.3? */
841 return(KMIP_OK);
842 break;
843
844 /* KMIP 1.2 */
845 case KMIP_OBJTYPE_PGP_KEY:
846 if(version >= KMIP_1_2)
847 return(KMIP_OK);
848 else
849 return(KMIP_INVALID_FOR_VERSION);
850 break;
851
852 /* KMIP 2.0 */
853 case KMIP_OBJTYPE_CERTIFICATE_REQUEST:
854 if(version >= KMIP_2_0)
855 return(KMIP_OK);
856 else
857 return(KMIP_INVALID_FOR_VERSION);
858 break;
859
860 default:
861 return(KMIP_ENUM_MISMATCH);
862 break;
863 };
864 break;
865
866 case KMIP_TAG_OPERATION:
867 switch(value)
868 {
869 /* KMIP 1.0 */
870 case KMIP_OP_CREATE:
871 case KMIP_OP_GET:
872 case KMIP_OP_GET_ATTRIBUTES:
873 case KMIP_OP_DESTROY:
874 case KMIP_OP_QUERY:
875 case KMIP_OP_LOCATE:
876 case KMIP_OP_REGISTER:
877 return(KMIP_OK);
878 break;
879
880 default:
881 return(KMIP_ENUM_MISMATCH);
882 break;
883 };
884 break;
885
886 case KMIP_TAG_PADDING_METHOD:
887 switch(value)
888 {
889 /* KMIP 1.0 */
890 case KMIP_PAD_NONE:
891 case KMIP_PAD_OAEP:
892 case KMIP_PAD_PKCS5:
893 case KMIP_PAD_SSL3:
894 case KMIP_PAD_ZEROS:
895 case KMIP_PAD_ANSI_X923:
896 case KMIP_PAD_ISO_10126:
897 case KMIP_PAD_PKCS1v15:
898 case KMIP_PAD_X931:
899 case KMIP_PAD_PSS:
900 return(KMIP_OK);
901 break;
902
903 default:
904 return(KMIP_ENUM_MISMATCH);
905 break;
906 };
907 break;
908
909 case KMIP_TAG_PROTECTION_STORAGE_MASK:
910 {
911 switch(value)
912 {
913 /* KMIP 2.0 */
914 case KMIP_PROTECT_SOFTWARE:
915 case KMIP_PROTECT_HARDWARE:
916 case KMIP_PROTECT_ON_PROCESSOR:
917 case KMIP_PROTECT_ON_SYSTEM:
918 case KMIP_PROTECT_OFF_SYSTEM:
919 case KMIP_PROTECT_HYPERVISOR:
920 case KMIP_PROTECT_OPERATING_SYSTEM:
921 case KMIP_PROTECT_CONTAINER:
922 case KMIP_PROTECT_ON_PREMISES:
923 case KMIP_PROTECT_OFF_PREMISES:
924 case KMIP_PROTECT_SELF_MANAGED:
925 case KMIP_PROTECT_OUTSOURCED:
926 case KMIP_PROTECT_VALIDATED:
927 case KMIP_PROTECT_SAME_JURISDICTION:
928 if(version >= KMIP_2_0)
929 return(KMIP_OK);
930 else
931 return(KMIP_INVALID_FOR_VERSION);
932 break;
933
934 default:
935 return(KMIP_ENUM_MISMATCH);
936 break;
937 };
938 };
939 break;
940
941 case KMIP_TAG_RESULT_REASON:
942 switch(value)
943 {
944 /* KMIP 1.0 */
945 case KMIP_REASON_GENERAL_FAILURE:
946 case KMIP_REASON_ITEM_NOT_FOUND:
947 case KMIP_REASON_RESPONSE_TOO_LARGE:
948 case KMIP_REASON_AUTHENTICATION_NOT_SUCCESSFUL:
949 case KMIP_REASON_INVALID_MESSAGE:
950 case KMIP_REASON_OPERATION_NOT_SUPPORTED:
951 case KMIP_REASON_MISSING_DATA:
952 case KMIP_REASON_INVALID_FIELD:
953 case KMIP_REASON_FEATURE_NOT_SUPPORTED:
954 case KMIP_REASON_OPERATION_CANCELED_BY_REQUESTER:
955 case KMIP_REASON_CRYPTOGRAPHIC_FAILURE:
956 case KMIP_REASON_ILLEGAL_OPERATION:
957 case KMIP_REASON_PERMISSION_DENIED:
958 case KMIP_REASON_OBJECT_ARCHIVED:
959 case KMIP_REASON_INDEX_OUT_OF_BOUNDS:
960 case KMIP_REASON_APPLICATION_NAMESPACE_NOT_SUPPORTED:
961 case KMIP_REASON_KEY_FORMAT_TYPE_NOT_SUPPORTED:
962 case KMIP_REASON_KEY_COMPRESSION_TYPE_NOT_SUPPORTED:
963 return(KMIP_OK);
964 break;
965
966 /* KMIP 1.1 */
967 case KMIP_REASON_ENCODING_OPTION_FAILURE:
968 if(version >= KMIP_1_1)
969 return(KMIP_OK);
970 else
971 return(KMIP_INVALID_FOR_VERSION);
972 break;
973
974 /* KMIP 1.2 */
975 case KMIP_REASON_KEY_VALUE_NOT_PRESENT:
976 case KMIP_REASON_ATTESTATION_REQUIRED:
977 case KMIP_REASON_ATTESTATION_FAILED:
978 if(version >= KMIP_1_2)
979 return(KMIP_OK);
980 else
981 return(KMIP_INVALID_FOR_VERSION);
982 break;
983
984 /* KMIP 1.4 */
985 case KMIP_REASON_SENSITIVE:
986 case KMIP_REASON_NOT_EXTRACTABLE:
987 case KMIP_REASON_OBJECT_ALREADY_EXISTS:
988 if(version >= KMIP_1_4)
989 return(KMIP_OK);
990 else
991 return(KMIP_INVALID_FOR_VERSION);
992 break;
993
994 /* KMIP 2.0 */
995 case KMIP_REASON_INVALID_TICKET:
996 case KMIP_REASON_USAGE_LIMIT_EXCEEDED:
997 case KMIP_REASON_NUMERIC_RANGE:
998 case KMIP_REASON_INVALID_DATA_TYPE:
999 case KMIP_REASON_READ_ONLY_ATTRIBUTE:
1000 case KMIP_REASON_MULTI_VALUED_ATTRIBUTE:
1001 case KMIP_REASON_UNSUPPORTED_ATTRIBUTE:
1002 case KMIP_REASON_ATTRIBUTE_INSTANCE_NOT_FOUND:
1003 case KMIP_REASON_ATTRIBUTE_NOT_FOUND:
1004 case KMIP_REASON_ATTRIBUTE_READ_ONLY:
1005 case KMIP_REASON_ATTRIBUTE_SINGLE_VALUED:
1006 case KMIP_REASON_BAD_CRYPTOGRAPHIC_PARAMETERS:
1007 case KMIP_REASON_BAD_PASSWORD:
1008 case KMIP_REASON_CODEC_ERROR:
1009 case KMIP_REASON_ILLEGAL_OBJECT_TYPE:
1010 case KMIP_REASON_INCOMPATIBLE_CRYPTOGRAPHIC_USAGE_MASK:
1011 case KMIP_REASON_INTERNAL_SERVER_ERROR:
1012 case KMIP_REASON_INVALID_ASYNCHRONOUS_CORRELATION_VALUE:
1013 case KMIP_REASON_INVALID_ATTRIBUTE:
1014 case KMIP_REASON_INVALID_ATTRIBUTE_VALUE:
1015 case KMIP_REASON_INVALID_CORRELATION_VALUE:
1016 case KMIP_REASON_INVALID_CSR:
1017 case KMIP_REASON_INVALID_OBJECT_TYPE:
1018 case KMIP_REASON_KEY_WRAP_TYPE_NOT_SUPPORTED:
1019 case KMIP_REASON_MISSING_INITIALIZATION_VECTOR:
1020 case KMIP_REASON_NON_UNIQUE_NAME_ATTRIBUTE:
1021 case KMIP_REASON_OBJECT_DESTROYED:
1022 case KMIP_REASON_OBJECT_NOT_FOUND:
1023 case KMIP_REASON_NOT_AUTHORISED:
1024 case KMIP_REASON_SERVER_LIMIT_EXCEEDED:
1025 case KMIP_REASON_UNKNOWN_ENUMERATION:
1026 case KMIP_REASON_UNKNOWN_MESSAGE_EXTENSION:
1027 case KMIP_REASON_UNKNOWN_TAG:
1028 case KMIP_REASON_UNSUPPORTED_CRYPTOGRAPHIC_PARAMETERS:
1029 case KMIP_REASON_UNSUPPORTED_PROTOCOL_VERSION:
1030 case KMIP_REASON_WRAPPING_OBJECT_ARCHIVED:
1031 case KMIP_REASON_WRAPPING_OBJECT_DESTROYED:
1032 case KMIP_REASON_WRAPPING_OBJECT_NOT_FOUND:
1033 case KMIP_REASON_WRONG_KEY_LIFECYCLE_STATE:
1034 case KMIP_REASON_PROTECTION_STORAGE_UNAVAILABLE:
1035 case KMIP_REASON_PKCS11_CODEC_ERROR:
1036 case KMIP_REASON_PKCS11_INVALID_FUNCTION:
1037 case KMIP_REASON_PKCS11_INVALID_INTERFACE:
1038 case KMIP_REASON_PRIVATE_PROTECTION_STORAGE_UNAVAILABLE:
1039 case KMIP_REASON_PUBLIC_PROTECTION_STORAGE_UNAVAILABLE:
1040 if(version >= KMIP_2_0)
1041 return(KMIP_OK);
1042 else
1043 return(KMIP_INVALID_FOR_VERSION);
1044 break;
1045
1046 default:
1047 return(KMIP_ENUM_MISMATCH);
1048 break;
1049 };
1050 break;
1051
1052 case KMIP_TAG_RESULT_STATUS:
1053 switch(value)
1054 {
1055 /* KMIP 1.0 */
1056 case KMIP_STATUS_SUCCESS:
1057 case KMIP_STATUS_OPERATION_FAILED:
1058 case KMIP_STATUS_OPERATION_PENDING:
1059 case KMIP_STATUS_OPERATION_UNDONE:
1060 return(KMIP_OK);
1061 break;
1062
1063 default:
1064 return(KMIP_ENUM_MISMATCH);
1065 break;
1066 };
1067 break;
1068
1069 case KMIP_TAG_STATE:
1070 switch(value)
1071 {
1072 /* KMIP 1.0 */
1073 case KMIP_STATE_PRE_ACTIVE:
1074 case KMIP_STATE_ACTIVE:
1075 case KMIP_STATE_DEACTIVATED:
1076 case KMIP_STATE_COMPROMISED:
1077 case KMIP_STATE_DESTROYED:
1078 case KMIP_STATE_DESTROYED_COMPROMISED:
1079 return(KMIP_OK);
1080 break;
1081
1082 default:
1083 return(KMIP_ENUM_MISMATCH);
1084 break;
1085 };
1086 break;
1087
1088 case KMIP_TAG_TAG:
1089 return(KMIP_OK);
1090 break;
1091
1092 case KMIP_TAG_TYPE:
1093 switch(value)
1094 {
1095 /* KMIP 1.0 */
1096 case KMIP_TYPE_STRUCTURE:
1097 case KMIP_TYPE_INTEGER:
1098 case KMIP_TYPE_LONG_INTEGER:
1099 case KMIP_TYPE_BIG_INTEGER:
1100 case KMIP_TYPE_ENUMERATION:
1101 case KMIP_TYPE_BOOLEAN:
1102 case KMIP_TYPE_TEXT_STRING:
1103 case KMIP_TYPE_BYTE_STRING:
1104 case KMIP_TYPE_DATE_TIME:
1105 case KMIP_TYPE_INTERVAL:
1106 return(KMIP_OK);
1107 break;
1108
1109 /* KMIP 2.0 */
1110 case KMIP_TYPE_DATE_TIME_EXTENDED:
1111 if(version >= KMIP_2_0)
1112 return(KMIP_OK);
1113 else
1114 return(KMIP_INVALID_FOR_VERSION);
1115 break;
1116
1117 default:
1118 return(KMIP_ENUM_MISMATCH);
1119 break;
1120 };
1121 break;
1122
1123 case KMIP_TAG_WRAPPING_METHOD:
1124 switch(value)
1125 {
1126 /* KMIP 1.0 */
1127 case KMIP_WRAP_ENCRYPT:
1128 case KMIP_WRAP_MAC_SIGN:
1129 case KMIP_WRAP_ENCRYPT_MAC_SIGN:
1130 case KMIP_WRAP_MAC_SIGN_ENCRYPT:
1131 case KMIP_WRAP_TR31:
1132 return(KMIP_OK);
1133 break;
1134
1135 default:
1136 return(KMIP_ENUM_MISMATCH);
1137 break;
1138 };
1139 break;
1140
1141 case KMIP_TAG_QUERY_FUNCTION:
1142 switch (value)
1143 {
1144 /* KMIP 1.0 */
1145 case KMIP_QUERY_OPERATIONS:
1146 case KMIP_QUERY_OBJECTS:
1147 case KMIP_QUERY_SERVER_INFORMATION:
1148 case KMIP_QUERY_APPLICATION_NAMESPACES:
1149 return(KMIP_OK);
1150 break;
1151
1152 /* KMIP 1.1 */
1153 case KMIP_QUERY_EXTENSION_LIST:
1154 case KMIP_QUERY_EXTENSION_MAP:
1155 {
1156 if(version >= KMIP_1_1)
1157 return(KMIP_OK);
1158 else
1159 return(KMIP_INVALID_FOR_VERSION);
1160 }
1161 break;
1162
1163 /* KMIP 1.2 */
1164 case KMIP_QUERY_ATTESTATION_TYPES:
1165 {
1166 if(version >= KMIP_1_2)
1167 return(KMIP_OK);
1168 else
1169 return(KMIP_INVALID_FOR_VERSION);
1170 }
1171 break;
1172
1173 /* KMIP 1.3 */
1174 case KMIP_QUERY_RNGS:
1175 case KMIP_QUERY_VALIDATIONS:
1176 case KMIP_QUERY_PROFILES:
1177 case KMIP_QUERY_CAPABILITIES:
1178 case KMIP_QUERY_CLIENT_REGISTRATION_METHODS:
1179 {
1180 if(version >= KMIP_1_3)
1181 return(KMIP_OK);
1182 else
1183 return(KMIP_INVALID_FOR_VERSION);
1184 }
1185 break;
1186
1187 /* KMIP 2.0 */
1188 case KMIP_QUERY_DEFAULTS_INFORMATION:
1189 case KMIP_QUERY_STORAGE_PROTECTION_MASKS:
1190 {
1191 if(version >= KMIP_2_0)
1192 return(KMIP_OK);
1193 else
1194 return(KMIP_INVALID_FOR_VERSION);
1195 }
1196 break;
1197
1198 default:
1199 return(KMIP_ENUM_MISMATCH);
1200 break;
1201 }
1202 break;
1203
1204 default:
1205 return(KMIP_ENUM_UNSUPPORTED);
1206 break;
1207 };
1208 }
1209
1210 /*
1211 Context Utilities
1212 */
1213
1214 void
1215 kmip_clear_errors(KMIP *ctx)
1216 {
1217 if(ctx == NULL)
1218 {
1219 return;
1220 }
1221
1222 for(size_t i = 0; i < ARRAY_LENGTH(ctx->errors); i++)
1223 {
1224 ctx->errors[i] = (ErrorFrame){{0},0};
1225 }
1226 ctx->frame_index = ctx->errors;
1227
1228 if(ctx->error_message != NULL)
1229 {
1230 ctx->free_func(ctx->state, ctx->error_message);
1231 ctx->error_message = NULL;
1232 }
1233 }
1234
1235 void
1236 kmip_init(KMIP *ctx, void *buffer, size_t buffer_size, enum kmip_version v)
1237 {
1238 if(ctx == NULL)
1239 {
1240 return;
1241 }
1242
1243 ctx->buffer = (uint8 *)buffer;
1244 ctx->index = ctx->buffer;
1245 ctx->size = buffer_size;
1246 ctx->version = v;
1247
1248 if(ctx->calloc_func == NULL)
1249 {
1250 ctx->calloc_func = &kmip_calloc;
1251 }
1252 if(ctx->realloc_func == NULL)
1253 {
1254 ctx->realloc_func = &kmip_realloc;
1255 }
1256 if(ctx->memset_func == NULL)
1257 {
1258 ctx->memset_func = &kmip_memset;
1259 }
1260 if(ctx->free_func == NULL)
1261 {
1262 ctx->free_func = &kmip_free;
1263 }
1264 if(ctx->memcpy_func == NULL)
1265 ctx->memcpy_func = &kmip_memcpy;
1266
1267 ctx->max_message_size = 8192;
1268 ctx->error_message_size = 200;
1269 ctx->error_message = NULL;
1270
1271 ctx->error_frame_count = 20;
1272
1273 ctx->credential_list = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
1274
1275 kmip_clear_errors(ctx);
1276 }
1277
1278 void
1279 kmip_init_error_message(KMIP *ctx)
1280 {
1281 if(ctx == NULL)
1282 {
1283 return;
1284 }
1285
1286 if(ctx->error_message == NULL)
1287 {
1288 ctx->error_message = ctx->calloc_func(ctx->state, ctx->error_message_size, sizeof(char));
1289 }
1290 }
1291
1292 int
1293 kmip_add_credential(KMIP *ctx, Credential *cred)
1294 {
1295 if(ctx == NULL || cred == NULL)
1296 {
1297 return(KMIP_UNSET);
1298 }
1299
1300 LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
1301 if(item != NULL)
1302 {
1303 item->data = cred;
1304 kmip_linked_list_push(ctx->credential_list, item);
1305 return(KMIP_OK);
1306 }
1307
1308 return(KMIP_UNSET);
1309 }
1310
1311 void
1312 kmip_remove_credentials(KMIP *ctx)
1313 {
1314 if(ctx == NULL)
1315 {
1316 return;
1317 }
1318
1319 LinkedListItem *item = kmip_linked_list_pop(ctx->credential_list);
1320 while(item != NULL)
1321 {
1322 ctx->memset_func(item, 0, sizeof(LinkedListItem));
1323 ctx->free_func(ctx->state, item);
1324
1325 item = kmip_linked_list_pop(ctx->credential_list);
1326 }
1327 }
1328
1329 void
1330 kmip_reset(KMIP *ctx)
1331 {
1332 if(ctx == NULL)
1333 {
1334 return;
1335 }
1336
1337 if(ctx->buffer != NULL)
1338 {
1339 kmip_memset(ctx->buffer, 0, ctx->size);
1340 }
1341 ctx->index = ctx->buffer;
1342
1343 kmip_clear_errors(ctx);
1344 }
1345
1346 void
1347 kmip_rewind(KMIP *ctx)
1348 {
1349 if(ctx == NULL)
1350 {
1351 return;
1352 }
1353
1354 ctx->index = ctx->buffer;
1355
1356 kmip_clear_errors(ctx);
1357 }
1358
1359 void
1360 kmip_set_buffer(KMIP *ctx, void *buffer, size_t buffer_size)
1361 {
1362 if(ctx == NULL)
1363 {
1364 return;
1365 }
1366
1367 /* TODO (ph) Add own_buffer if buffer == NULL? */
1368 ctx->buffer = (uint8 *)buffer;
1369 ctx->index = ctx->buffer;
1370 ctx->size = buffer_size;
1371 }
1372
1373 void
1374 kmip_destroy(KMIP *ctx)
1375 {
1376 if(ctx == NULL)
1377 {
1378 return;
1379 }
1380
1381 kmip_reset(ctx);
1382 kmip_set_buffer(ctx, NULL, 0);
1383
1384 kmip_remove_credentials(ctx);
1385 ctx->memset_func(ctx->credential_list, 0, sizeof(LinkedList));
1386 ctx->free_func(ctx->state, ctx->credential_list);
1387
1388 ctx->calloc_func = NULL;
1389 ctx->realloc_func = NULL;
1390 ctx->memset_func = NULL;
1391 ctx->free_func = NULL;
1392 ctx->memcpy_func = NULL;
1393 ctx->state = NULL;
1394 }
1395
1396 void
1397 kmip_push_error_frame(KMIP *ctx, const char *function, const int line)
1398 {
1399 if(ctx == NULL)
1400 {
1401 return;
1402 }
1403
1404 for(size_t i = 0; i < 20; i++)
1405 {
1406 ErrorFrame *frame = &ctx->errors[i];
1407 if(frame->line == 0)
1408 {
1409 ctx->frame_index = frame;
1410 strncpy(frame->function, function, sizeof(frame->function) - 1);
1411 frame->line = line;
1412 break;
1413 }
1414 }
1415 }
1416
1417 void
1418 kmip_set_enum_error_message(KMIP *ctx, enum tag t, int value, int result)
1419 {
1420 if(ctx == NULL)
1421 {
1422 return;
1423 }
1424
1425 switch(result)
1426 {
1427 /* TODO (ph) Update error message for KMIP version 2.0+ */
1428 case KMIP_INVALID_FOR_VERSION:
1429 kmip_init_error_message(ctx);
1430 snprintf(ctx->error_message, ctx->error_message_size, "KMIP 1.%d does not support %s enumeration value (%d)", ctx->version, kmip_attribute_names[kmip_get_enum_string_index(t)], value);
1431 break;
1432
1433 default: /* KMIP_ENUM_MISMATCH */
1434 kmip_init_error_message(ctx);
1435 snprintf(ctx->error_message, ctx->error_message_size, "Invalid %s enumeration value (%d)", kmip_attribute_names[kmip_get_enum_string_index(t)], value);
1436 break;
1437 };
1438 }
1439
1440 void
1441 kmip_set_alloc_error_message(KMIP *ctx, size_t size, const char *type)
1442 {
1443 if(ctx == NULL)
1444 {
1445 return;
1446 }
1447
1448 kmip_init_error_message(ctx);
1449 snprintf(ctx->error_message, ctx->error_message_size, "Could not allocate %zd bytes for a %s", size, type);
1450 }
1451
1452 void
1453 kmip_set_error_message(KMIP *ctx, const char *message)
1454 {
1455 if(ctx == NULL)
1456 {
1457 return;
1458 }
1459
1460 kmip_init_error_message(ctx);
1461 snprintf(ctx->error_message, ctx->error_message_size, "%s", message);
1462 }
1463
1464 int
1465 kmip_is_tag_next(const KMIP *ctx, enum tag t)
1466 {
1467 if(ctx == NULL)
1468 {
1469 return(KMIP_FALSE);
1470 }
1471
1472 uint8 *index = ctx->index;
1473
1474 if((ctx->size - (uint64)(index - ctx->buffer)) < 3)
1475 {
1476 return(KMIP_FALSE);
1477 }
1478
1479 uint32 tag = 0;
1480
1481 tag |= ((uint32)*index++ << 16);
1482 tag |= ((uint32)*index++ << 8);
1483 tag |= ((uint32)*index << 0);
1484
1485 if(tag != t)
1486 {
1487 return(KMIP_FALSE);
1488 }
1489
1490 return(KMIP_TRUE);
1491 }
1492
1493 int
1494 kmip_is_tag_type_next(const KMIP *ctx, enum tag t, enum type s)
1495 {
1496 if(ctx == NULL)
1497 {
1498 return(KMIP_FALSE);
1499 }
1500
1501 uint8 *index = ctx->index;
1502
1503 if((ctx->size - (uint64)(index - ctx->buffer)) < 4)
1504 {
1505 return(KMIP_FALSE);
1506 }
1507
1508 uint32 tag_type = 0;
1509
1510 tag_type |= ((uint32)*index++ << 24);
1511 tag_type |= ((uint32)*index++ << 16);
1512 tag_type |= ((uint32)*index++ << 8);
1513 tag_type |= ((uint32)*index << 0);
1514
1515 if(tag_type != TAG_TYPE(t, s))
1516 {
1517 return(KMIP_FALSE);
1518 }
1519
1520 return(KMIP_TRUE);
1521 }
1522
1523 size_t
1524 kmip_get_num_items_next(KMIP *ctx, enum tag t)
1525 {
1526 if(ctx == NULL)
1527 {
1528 return(0);
1529 }
1530
1531 size_t count = 0;
1532
1533 uint8 *index = ctx->index;
1534 uint32 length = 0;
1535
1536 while((ctx->size - (uint64)(ctx->index - ctx->buffer)) > 8)
1537 {
1538 if(kmip_is_tag_next(ctx, t))
1539 {
1540 ctx->index += 4;
1541
1542 length = 0;
1543 length |= ((int32)*ctx->index++ << 24);
1544 length |= ((int32)*ctx->index++ << 16);
1545 length |= ((int32)*ctx->index++ << 8);
1546 length |= ((int32)*ctx->index++ << 0);
1547 length += CALCULATE_PADDING(length);
1548
1549 if((ctx->size - (ctx->index - ctx->buffer)) >= length)
1550 {
1551 ctx->index += length;
1552 count++;
1553 }
1554 else
1555 {
1556 break;
1557 }
1558 }
1559 else
1560 {
1561 break;
1562 }
1563 }
1564
1565 ctx->index = index;
1566 return(count);
1567 }
1568
1569 uint32
1570 kmip_peek_tag(KMIP *ctx)
1571 {
1572 if(BUFFER_BYTES_LEFT(ctx) < 3)
1573 {
1574 return(0);
1575 }
1576
1577 uint8 *index = ctx->index;
1578 uint32 tag = 0;
1579
1580 tag |= ((int32)*index++ << 16);
1581 tag |= ((int32)*index++ << 8);
1582 tag |= ((int32)*index << 0);
1583
1584 return(tag);
1585 }
1586
1587 int
1588 kmip_is_attribute_tag(uint32 value)
1589 {
1590 enum tag attribute_tags[] = {
1591 KMIP_TAG_UNIQUE_IDENTIFIER,
1592 KMIP_TAG_NAME,
1593 KMIP_TAG_OBJECT_TYPE,
1594 KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM,
1595 KMIP_TAG_CRYPTOGRAPHIC_LENGTH,
1596 KMIP_TAG_OPERATION_POLICY_NAME,
1597 KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK,
1598 KMIP_TAG_STATE
1599 };
1600
1601 for(size_t i = 0; i < ARRAY_LENGTH(attribute_tags); i++)
1602 {
1603 if(attribute_tags[i] == value)
1604 {
1605 return(KMIP_TRUE);
1606 }
1607 }
1608
1609 return(KMIP_FALSE);
1610 }
1611
1612 /*
1613 Initialization Functions
1614 */
1615
1616 void
1617 kmip_init_application_specific_information(ApplicationSpecificInformation *value)
1618 {
1619 if(value == NULL)
1620 {
1621 return;
1622 }
1623
1624 value->application_namespace = NULL;
1625 value->application_data = NULL;
1626 }
1627
1628 void
1629 kmip_init_protocol_version(ProtocolVersion *value, enum kmip_version kmip_version)
1630 {
1631 if(value == NULL)
1632 {
1633 return;
1634 }
1635
1636 switch(kmip_version)
1637 {
1638 case KMIP_2_0:
1639 {
1640 value->major = 2;
1641 value->minor = 0;
1642 };
1643 break;
1644
1645 case KMIP_1_4:
1646 {
1647 value->major = 1;
1648 value->minor = 4;
1649 };
1650 break;
1651
1652 case KMIP_1_3:
1653 {
1654 value->major = 1;
1655 value->minor = 3;
1656 };
1657 break;
1658
1659 case KMIP_1_2:
1660 {
1661 value->major = 1;
1662 value->minor = 2;
1663 };
1664 break;
1665
1666 case KMIP_1_1:
1667 {
1668 value->major = 1;
1669 value->minor = 1;
1670 };
1671 break;
1672
1673 case KMIP_1_0:
1674 default:
1675 {
1676 value->major = 1;
1677 value->minor = 0;
1678 };
1679 break;
1680 };
1681 }
1682
1683 void
1684 kmip_init_attribute(Attribute *value)
1685 {
1686 if(value == NULL)
1687 {
1688 return;
1689 }
1690
1691 value->type = 0;
1692 value->index = KMIP_UNSET;
1693 value->value = NULL;
1694 }
1695
1696 void
1697 kmip_init_cryptographic_parameters(CryptographicParameters *value)
1698 {
1699 if(value == NULL)
1700 {
1701 return;
1702 }
1703
1704 value->block_cipher_mode = 0;
1705 value->padding_method = 0;
1706 value->hashing_algorithm = 0;
1707 value->key_role_type = 0;
1708
1709 value->digital_signature_algorithm = 0;
1710 value->cryptographic_algorithm = 0;
1711 value->random_iv = KMIP_UNSET;
1712 value->iv_length = KMIP_UNSET;
1713 value->tag_length = KMIP_UNSET;
1714 value->fixed_field_length = KMIP_UNSET;
1715 value->invocation_field_length = KMIP_UNSET;
1716 value->counter_length = KMIP_UNSET;
1717 value->initial_counter_value = KMIP_UNSET;
1718
1719 value->salt_length = KMIP_UNSET;
1720 value->mask_generator = 0;
1721 value->mask_generator_hashing_algorithm = 0;
1722 value->p_source = NULL;
1723 value->trailer_field = KMIP_UNSET;
1724 }
1725
1726 void
1727 kmip_init_key_block(KeyBlock *value)
1728 {
1729 if(value == NULL)
1730 {
1731 return;
1732 }
1733
1734 value->key_format_type = 0;
1735 value->key_compression_type = 0;
1736 value->key_value = NULL;
1737 value->key_value_type = 0;
1738 value->cryptographic_algorithm = 0;
1739 value->cryptographic_length = KMIP_UNSET;
1740 value->key_wrapping_data = NULL;
1741 }
1742
1743 void
1744 kmip_init_request_header(RequestHeader *value)
1745 {
1746 if(value == NULL)
1747 {
1748 return;
1749 }
1750
1751 value->protocol_version = NULL;
1752 value->maximum_response_size = KMIP_UNSET;
1753 value->asynchronous_indicator = KMIP_UNSET;
1754 value->authentication = NULL;
1755 value->batch_error_continuation_option = 0;
1756 value->batch_order_option = KMIP_UNSET;
1757 value->time_stamp = 0;
1758 value->batch_count = KMIP_UNSET;
1759
1760 value->attestation_capable_indicator = KMIP_UNSET;
1761 value->attestation_types = NULL;
1762 value->attestation_type_count = 0;
1763
1764 value->client_correlation_value = NULL;
1765 value->server_correlation_value = NULL;
1766 }
1767
1768 void
1769 kmip_init_response_header(ResponseHeader *value)
1770 {
1771 if(value == NULL)
1772 {
1773 return;
1774 }
1775
1776 value->protocol_version = NULL;
1777 value->time_stamp = 0;
1778 value->batch_count = KMIP_UNSET;
1779
1780 value->nonce = NULL;
1781 value->attestation_types = NULL;
1782 value->attestation_type_count = 0;
1783
1784 value->client_correlation_value = NULL;
1785 value->server_correlation_value = NULL;
1786
1787 value->server_hashed_password = NULL;
1788 }
1789
1790 void
1791 kmip_init_request_batch_item(RequestBatchItem *value)
1792 {
1793 if(value == NULL)
1794 {
1795 return;
1796 }
1797
1798 value->operation = 0;
1799 value->unique_batch_item_id = NULL;
1800 value->request_payload = NULL;
1801
1802 value->ephemeral = KMIP_UNSET;
1803 }
1804
1805 /*
1806 Printing Functions
1807 */
1808
1809 void
1810 kmip_print_buffer(FILE *f, void *buffer, int size)
1811 {
1812 if(buffer == NULL)
1813 {
1814 return;
1815 }
1816
1817 uint8 *index = (uint8 *)buffer;
1818 for(int i = 0; i < size; i++)
1819 {
1820 if(i % 16 == 0)
1821 {
1822 fprintf(f, "\n0x");
1823 }
1824 fprintf(f, "%02X", index[i]);
1825 }
1826 }
1827
1828 void
1829 kmip_print_stack_trace(FILE *f, KMIP *ctx)
1830 {
1831 if(ctx == NULL)
1832 {
1833 return;
1834 }
1835
1836 ErrorFrame *index = ctx->frame_index;
1837 do
1838 {
1839 fprintf(f, "- %s @ line: %d\n", index->function, index->line);
1840 } while(index-- != ctx->errors);
1841 }
1842
1843 void
1844 kmip_print_error_string(FILE *f, int value)
1845 {
1846 /* TODO (ph) Move this to a static string array. */
1847 switch(value)
1848 {
1849 case 0:
1850 {
1851 fprintf(f, "KMIP_OK");
1852 } break;
1853
1854 case -1:
1855 {
1856 fprintf(f, "KMIP_NOT_IMPLEMENTED");
1857 } break;
1858
1859 case -2:
1860 {
1861 fprintf(f, "KMIP_ERROR_BUFFER_FULL");
1862 } break;
1863
1864 case -3:
1865 {
1866 fprintf(f, "KMIP_ERROR_ATTR_UNSUPPORTED");
1867 } break;
1868
1869 case -4:
1870 {
1871 fprintf(f, "KMIP_TAG_MISMATCH");
1872 } break;
1873
1874 case -5:
1875 {
1876 fprintf(f, "KMIP_TYPE_MISMATCH");
1877 } break;
1878
1879 case -6:
1880 {
1881 fprintf(f, "KMIP_LENGTH_MISMATCH");
1882 } break;
1883
1884 case -7:
1885 {
1886 fprintf(f, "KMIP_PADDING_MISMATCH");
1887 } break;
1888
1889 case -8:
1890 {
1891 fprintf(f, "KMIP_BOOLEAN_MISMATCH");
1892 } break;
1893
1894 case -9:
1895 {
1896 fprintf(f, "KMIP_ENUM_MISMATCH");
1897 } break;
1898
1899 case -10:
1900 {
1901 fprintf(f, "KMIP_ENUM_UNSUPPORTED");
1902 } break;
1903
1904 case -11:
1905 {
1906 fprintf(f, "KMIP_INVALID_FOR_VERSION");
1907 } break;
1908
1909 case -12:
1910 {
1911 fprintf(f, "KMIP_MEMORY_ALLOC_FAILED");
1912 } break;
1913
1914 case -13:
1915 {
1916 fprintf(f, "KMIP_IO_FAILURE");
1917 } break;
1918
1919 case -14:
1920 {
1921 fprintf(f, "KMIP_EXCEED_MAX_MESSAGE_SIZE");
1922 } break;
1923
1924 case -15:
1925 {
1926 fprintf(f, "KMIP_MALFORMED_RESPONSE");
1927 } break;
1928
1929 case -16:
1930 {
1931 fprintf(f, "KMIP_OBJECT_MISMATCH");
1932 } break;
1933
1934 case -17:
1935 {
1936 fprintf(f, "KMIP_ARG_INVALID");
1937 } break;
1938
1939 case -18:
1940 {
1941 fprintf(f, "KMIP_ERROR_BUFFER_UNDERFULL");
1942 } break;
1943
1944 default:
1945 {
1946 fprintf(f, "Unrecognized Error Code");
1947 } break;
1948 };
1949
1950 return;
1951 }
1952
1953 void
1954 kmip_print_attestation_type_enum(FILE *f, enum attestation_type value)
1955 {
1956 if(value == 0)
1957 {
1958 fprintf(f, "-");
1959 return;
1960 }
1961
1962 switch(value)
1963 {
1964 case KMIP_ATTEST_TPM_QUOTE:
1965 fprintf(f, "TPM Quote");
1966 break;
1967
1968 case KMIP_ATTEST_TCG_INTEGRITY_REPORT:
1969 fprintf(f, "TCG Integrity Report");
1970 break;
1971
1972 case KMIP_ATTEST_SAML_ASSERTION:
1973 fprintf(f, "SAML Assertion");
1974 break;
1975
1976 default:
1977 fprintf(f, "Unknown");
1978 break;
1979 };
1980 }
1981
1982 void
1983 kmip_print_batch_error_continuation_option(FILE *f, enum batch_error_continuation_option value)
1984 {
1985 if(value == 0)
1986 {
1987 fprintf(f, "-");
1988 return;
1989 }
1990
1991 switch(value)
1992 {
1993 case KMIP_BATCH_CONTINUE:
1994 fprintf(f, "Continue");
1995 break;
1996
1997 case KMIP_BATCH_STOP:
1998 fprintf(f, "Stop");
1999 break;
2000
2001 case KMIP_BATCH_UNDO:
2002 fprintf(f, "Undo");
2003 break;
2004
2005 default:
2006 fprintf(f, "Unknown");
2007 break;
2008 };
2009 }
2010
2011 void
2012 kmip_print_operation_enum(FILE *f, enum operation value)
2013 {
2014 if(value == 0)
2015 {
2016 fprintf(f, "-");
2017 return;
2018 }
2019
2020 switch(value)
2021 {
2022 case KMIP_OP_CREATE:
2023 fprintf(f, "Create");
2024 break;
2025
2026 case KMIP_OP_CREATE_KEY_PAIR:
2027 fprintf(f, "Create Key Pair");
2028 break;
2029
2030 case KMIP_OP_REGISTER:
2031 fprintf(f, "Register");
2032 break;
2033
2034 case KMIP_OP_REKEY:
2035 fprintf(f, "Rekey");
2036 break;
2037
2038 case KMIP_OP_DERIVE_KEY:
2039 fprintf(f, "Derive Key");
2040 break;
2041
2042 case KMIP_OP_CERTIFY:
2043 fprintf(f, "Certify");
2044 break;
2045
2046 case KMIP_OP_RECERTIFY:
2047 fprintf(f, "Recertify");
2048 break;
2049
2050 case KMIP_OP_LOCATE:
2051 fprintf(f, "Locate");
2052 break;
2053
2054 case KMIP_OP_CHECK:
2055 fprintf(f, "Check");
2056 break;
2057
2058 case KMIP_OP_GET:
2059 fprintf(f, "Get");
2060 break;
2061
2062 case KMIP_OP_GET_ATTRIBUTES:
2063 fprintf(f, "Get Attributes");
2064 break;
2065
2066 case KMIP_OP_GET_ATTRIBUTE_LIST:
2067 fprintf(f, "Get Attribute List");
2068 break;
2069
2070 case KMIP_OP_ADD_ATTRIBUTE:
2071 fprintf(f, "Add Attribute");
2072 break;
2073
2074 case KMIP_OP_MODIFY_ATTRIBUTE:
2075 fprintf(f, "Modify Attribute");
2076 break;
2077
2078 case KMIP_OP_DELETE_ATTRIBUTE:
2079 fprintf(f, "Delete Attribute");
2080 break;
2081
2082 case KMIP_OP_OBTAIN_LEASE:
2083 fprintf(f, "Obtain Lease");
2084 break;
2085
2086 case KMIP_OP_GET_USAGE_ALLOCATION:
2087 fprintf(f, "Get Usage Allocation");
2088 break;
2089
2090 case KMIP_OP_ACTIVATE:
2091 fprintf(f, "Activate");
2092 break;
2093
2094 case KMIP_OP_REVOKE:
2095 fprintf(f, "Revoke");
2096 break;
2097
2098 case KMIP_OP_DESTROY:
2099 fprintf(f, "Destroy");
2100 break;
2101
2102 case KMIP_OP_ARCHIVE:
2103 fprintf(f, "Archive");
2104 break;
2105
2106 case KMIP_OP_RECOVER:
2107 fprintf(f, "Recover");
2108 break;
2109
2110 case KMIP_OP_VALIDATE:
2111 fprintf(f, "Validate");
2112 break;
2113
2114 case KMIP_OP_QUERY:
2115 printf("Query");
2116 break;
2117
2118 case KMIP_OP_CANCEL:
2119 fprintf(f, "Cancel");
2120 break;
2121
2122 case KMIP_OP_POLL:
2123 fprintf(f, "Poll");
2124 break;
2125
2126 case KMIP_OP_NOTIFY:
2127 fprintf(f, "Notify");
2128 break;
2129
2130 case KMIP_OP_PUT:
2131 fprintf(f, "Put");
2132 break;
2133
2134 // # KMIP 1.1
2135 case KMIP_OP_REKEY_KEY_PAIR:
2136 fprintf(f, "Rekey Key Pair");
2137 break;
2138
2139 case KMIP_OP_DISCOVER_VERSIONS:
2140 fprintf(f, "Discover Versions");
2141 break;
2142
2143 //# KMIP 1.2
2144 case KMIP_OP_ENCRYPT:
2145 fprintf(f, "Encrypt");
2146 break;
2147
2148 case KMIP_OP_DECRYPT:
2149 fprintf(f, "Decrypt");
2150 break;
2151
2152 case KMIP_OP_SIGN:
2153 fprintf(f, "Sign");
2154 break;
2155
2156 case KMIP_OP_SIGNATURE_VERIFY:
2157 fprintf(f, "Signature Verify");
2158 break;
2159
2160 case KMIP_OP_MAC:
2161 fprintf(f, "MAC");
2162 break;
2163
2164 case KMIP_OP_MAC_VERIFY:
2165 fprintf(f, "MAC Verify");
2166 break;
2167
2168 case KMIP_OP_RNG_RETRIEVE:
2169 fprintf(f, "RNG Retrieve");
2170 break;
2171
2172 case KMIP_OP_RNG_SEED:
2173 fprintf(f, "RNG Seed");
2174 break;
2175
2176 case KMIP_OP_HASH:
2177 fprintf(f, "Hash");
2178 break;
2179
2180 case KMIP_OP_CREATE_SPLIT_KEY:
2181 fprintf(f, "Create Split Key");
2182 break;
2183
2184 case KMIP_OP_JOIN_SPLIT_KEY:
2185 fprintf(f, "Split Key");
2186 break;
2187
2188 // # KMIP 1.4
2189 case KMIP_OP_IMPORT:
2190 fprintf(f, "Import");
2191 break;
2192
2193 case KMIP_OP_EXPORT:
2194 fprintf(f, "Export");
2195 break;
2196
2197 // # KMIP 2.0
2198 case KMIP_OP_LOG:
2199 fprintf(f, "Log");
2200 break;
2201
2202 case KMIP_OP_LOGIN:
2203 fprintf(f, "Login");
2204 break;
2205
2206 case KMIP_OP_LOGOUT:
2207 fprintf(f, "Logout");
2208 break;
2209
2210 case KMIP_OP_DELEGATED_LOGIN:
2211 fprintf(f, "Delegated Login");
2212 break;
2213
2214 case KMIP_OP_ADJUST_ATTRIBUTE:
2215 fprintf(f, "Adjust Attribute");
2216 break;
2217
2218 case KMIP_OP_SET_ATTRIBUTE:
2219 fprintf(f, "Set Attribute");
2220 break;
2221
2222 case KMIP_OP_SET_ENDPOINT_ROLE:
2223 fprintf(f, "Set Endpoint Role");
2224 break;
2225
2226 case KMIP_OP_PKCS_11:
2227 fprintf(f, "PKCS11");
2228 break;
2229
2230 case KMIP_OP_INTEROP:
2231 fprintf(f, "Interop");
2232 break;
2233
2234 case KMIP_OP_REPROVISION:
2235 fprintf(f, "Reprovision");
2236 break;
2237
2238 default:
2239 fprintf(f, "Unknown");
2240 break;
2241 };
2242 }
2243
2244 void
2245 kmip_print_result_status_enum(FILE *f, enum result_status value)
2246 {
2247 switch(value)
2248 {
2249 case KMIP_STATUS_SUCCESS:
2250 fprintf(f, "Success");
2251 break;
2252
2253 case KMIP_STATUS_OPERATION_FAILED:
2254 fprintf(f, "Operation Failed");
2255 break;
2256
2257 case KMIP_STATUS_OPERATION_PENDING:
2258 fprintf(f, "Operation Pending");
2259 break;
2260
2261 case KMIP_STATUS_OPERATION_UNDONE:
2262 fprintf(f, "Operation Undone");
2263 break;
2264
2265 default:
2266 fprintf(f, "Unknown");
2267 break;
2268 };
2269 }
2270
2271 void
2272 kmip_print_result_reason_enum(FILE *f, enum result_reason value)
2273 {
2274 if(value == 0)
2275 {
2276 fprintf(f, "-");
2277 return;
2278 }
2279
2280 switch(value)
2281 {
2282 case KMIP_REASON_GENERAL_FAILURE:
2283 fprintf(f, "General Failure");
2284 break;
2285
2286 case KMIP_REASON_ITEM_NOT_FOUND:
2287 fprintf(f, "Item Not Found");
2288 break;
2289
2290 case KMIP_REASON_RESPONSE_TOO_LARGE:
2291 fprintf(f, "Response Too Large");
2292 break;
2293
2294 case KMIP_REASON_AUTHENTICATION_NOT_SUCCESSFUL:
2295 fprintf(f, "Authentication Not Successful");
2296 break;
2297
2298 case KMIP_REASON_INVALID_MESSAGE:
2299 fprintf(f, "Invalid Message");
2300 break;
2301
2302 case KMIP_REASON_OPERATION_NOT_SUPPORTED:
2303 fprintf(f, "Operation Not Supported");
2304 break;
2305
2306 case KMIP_REASON_MISSING_DATA:
2307 fprintf(f, "Missing Data");
2308 break;
2309
2310 case KMIP_REASON_INVALID_FIELD:
2311 fprintf(f, "Invalid Field");
2312 break;
2313
2314 case KMIP_REASON_FEATURE_NOT_SUPPORTED:
2315 fprintf(f, "Feature Not Supported");
2316 break;
2317
2318 case KMIP_REASON_OPERATION_CANCELED_BY_REQUESTER:
2319 fprintf(f, "Operation Canceled By Requester");
2320 break;
2321
2322 case KMIP_REASON_CRYPTOGRAPHIC_FAILURE:
2323 fprintf(f, "Cryptographic Failure");
2324 break;
2325
2326 case KMIP_REASON_ILLEGAL_OPERATION:
2327 fprintf(f, "Illegal Operation");
2328 break;
2329
2330 case KMIP_REASON_PERMISSION_DENIED:
2331 fprintf(f, "Permission Denied");
2332 break;
2333
2334 case KMIP_REASON_OBJECT_ARCHIVED:
2335 fprintf(f, "Object Archived");
2336 break;
2337
2338 case KMIP_REASON_INDEX_OUT_OF_BOUNDS:
2339 fprintf(f, "Index Out Of Bounds");
2340 break;
2341
2342 case KMIP_REASON_APPLICATION_NAMESPACE_NOT_SUPPORTED:
2343 fprintf(f, "Application Namespace Not Supported");
2344 break;
2345
2346 case KMIP_REASON_KEY_FORMAT_TYPE_NOT_SUPPORTED:
2347 fprintf(f, "Key Format Type Not Supported");
2348 break;
2349
2350 case KMIP_REASON_KEY_COMPRESSION_TYPE_NOT_SUPPORTED:
2351 fprintf(f, "Key Compression Type Not Supported");
2352 break;
2353
2354 case KMIP_REASON_ENCODING_OPTION_FAILURE:
2355 fprintf(f, "Encoding Option Failure");
2356 break;
2357
2358 case KMIP_REASON_KEY_VALUE_NOT_PRESENT:
2359 fprintf(f, "Key Value Not Present");
2360 break;
2361
2362 case KMIP_REASON_ATTESTATION_REQUIRED:
2363 fprintf(f, "Attestation Required");
2364 break;
2365
2366 case KMIP_REASON_ATTESTATION_FAILED:
2367 fprintf(f, "Attestation Failed");
2368 break;
2369
2370 case KMIP_REASON_SENSITIVE:
2371 fprintf(f, "Sensitive");
2372 break;
2373
2374 case KMIP_REASON_NOT_EXTRACTABLE:
2375 fprintf(f, "Not Extractable");
2376 break;
2377
2378 case KMIP_REASON_OBJECT_ALREADY_EXISTS:
2379 fprintf(f, "Object Already Exists");
2380 break;
2381
2382 case KMIP_REASON_INVALID_TICKET:
2383 fprintf(f, "Invalid Ticket");
2384 break;
2385
2386 case KMIP_REASON_USAGE_LIMIT_EXCEEDED:
2387 fprintf(f, "Usage Limit Exceeded");
2388 break;
2389
2390 case KMIP_REASON_NUMERIC_RANGE:
2391 fprintf(f, "Numeric Range");
2392 break;
2393
2394 case KMIP_REASON_INVALID_DATA_TYPE:
2395 fprintf(f, "Invalid Data Type");
2396 break;
2397
2398 case KMIP_REASON_READ_ONLY_ATTRIBUTE:
2399 fprintf(f, "Read Only Attribute");
2400 break;
2401
2402 case KMIP_REASON_MULTI_VALUED_ATTRIBUTE:
2403 fprintf(f, "Multi Valued Attribute");
2404 break;
2405
2406 case KMIP_REASON_UNSUPPORTED_ATTRIBUTE:
2407 fprintf(f, "Unsupported Attribute");
2408 break;
2409
2410 case KMIP_REASON_ATTRIBUTE_INSTANCE_NOT_FOUND:
2411 fprintf(f, "Attribute Instance Not Found");
2412 break;
2413
2414 case KMIP_REASON_ATTRIBUTE_NOT_FOUND:
2415 fprintf(f, "Attribute Not Found");
2416 break;
2417
2418 case KMIP_REASON_ATTRIBUTE_READ_ONLY:
2419 fprintf(f, "Attribute Read Only");
2420 break;
2421
2422 case KMIP_REASON_ATTRIBUTE_SINGLE_VALUED:
2423 fprintf(f, "Attribute Single Valued");
2424 break;
2425
2426 case KMIP_REASON_BAD_CRYPTOGRAPHIC_PARAMETERS:
2427 fprintf(f, "Bad Cryptographic Parameters");
2428 break;
2429
2430 case KMIP_REASON_BAD_PASSWORD:
2431 fprintf(f, "Bad Password");
2432 break;
2433
2434 case KMIP_REASON_CODEC_ERROR:
2435 fprintf(f, "Codec Error");
2436 break;
2437
2438 case KMIP_REASON_ILLEGAL_OBJECT_TYPE:
2439 fprintf(f, "Illegal Object Type");
2440 break;
2441
2442 case KMIP_REASON_INCOMPATIBLE_CRYPTOGRAPHIC_USAGE_MASK:
2443 fprintf(f, "Incompatible Cryptographic Usage Mask");
2444 break;
2445
2446 case KMIP_REASON_INTERNAL_SERVER_ERROR:
2447 fprintf(f, "Internal Server Error");
2448 break;
2449
2450 case KMIP_REASON_INVALID_ASYNCHRONOUS_CORRELATION_VALUE:
2451 fprintf(f, "Invalid Asynchronous Correlation Value");
2452 break;
2453
2454 case KMIP_REASON_INVALID_ATTRIBUTE:
2455 fprintf(f, "Invalid Attribute");
2456 break;
2457
2458 case KMIP_REASON_INVALID_ATTRIBUTE_VALUE:
2459 fprintf(f, "Invalid Attribute Value");
2460 break;
2461
2462 case KMIP_REASON_INVALID_CORRELATION_VALUE:
2463 fprintf(f, "Invalid Correlation Value");
2464 break;
2465
2466 case KMIP_REASON_INVALID_CSR:
2467 fprintf(f, "Invalid CSR");
2468 break;
2469
2470 case KMIP_REASON_INVALID_OBJECT_TYPE:
2471 fprintf(f, "Invalid Object Type");
2472 break;
2473
2474 case KMIP_REASON_KEY_WRAP_TYPE_NOT_SUPPORTED:
2475 fprintf(f, "Key Wrap Type Not Supported");
2476 break;
2477
2478 case KMIP_REASON_MISSING_INITIALIZATION_VECTOR:
2479 fprintf(f, "Missing Initialization Vector");
2480 break;
2481
2482 case KMIP_REASON_NON_UNIQUE_NAME_ATTRIBUTE:
2483 fprintf(f, "Non Unique Name Attribute");
2484 break;
2485
2486 case KMIP_REASON_OBJECT_DESTROYED:
2487 fprintf(f, "Object Destroyed");
2488 break;
2489
2490 case KMIP_REASON_OBJECT_NOT_FOUND:
2491 fprintf(f, "Object Not Found");
2492 break;
2493
2494 case KMIP_REASON_NOT_AUTHORISED:
2495 fprintf(f, "Not Authorised");
2496 break;
2497
2498 case KMIP_REASON_SERVER_LIMIT_EXCEEDED:
2499 fprintf(f, "Server Limit Exceeded");
2500 break;
2501
2502 case KMIP_REASON_UNKNOWN_ENUMERATION:
2503 fprintf(f, "Unknown Enumeration");
2504 break;
2505
2506 case KMIP_REASON_UNKNOWN_MESSAGE_EXTENSION:
2507 fprintf(f, "Unknown Message Extension");
2508 break;
2509
2510 case KMIP_REASON_UNKNOWN_TAG:
2511 fprintf(f, "Unknown Tag");
2512 break;
2513
2514 case KMIP_REASON_UNSUPPORTED_CRYPTOGRAPHIC_PARAMETERS:
2515 fprintf(f, "Unsupported Cryptographic Parameters");
2516 break;
2517
2518 case KMIP_REASON_UNSUPPORTED_PROTOCOL_VERSION:
2519 fprintf(f, "Unsupported Protocol Version");
2520 break;
2521
2522 case KMIP_REASON_WRAPPING_OBJECT_ARCHIVED:
2523 fprintf(f, "Wrapping Object Archived");
2524 break;
2525
2526 case KMIP_REASON_WRAPPING_OBJECT_DESTROYED:
2527 fprintf(f, "Wrapping Object Destroyed");
2528 break;
2529
2530 case KMIP_REASON_WRAPPING_OBJECT_NOT_FOUND:
2531 fprintf(f, "Wrapping Object Not Found");
2532 break;
2533
2534 case KMIP_REASON_WRONG_KEY_LIFECYCLE_STATE:
2535 fprintf(f, "Wrong Key Lifecycle State");
2536 break;
2537
2538 case KMIP_REASON_PROTECTION_STORAGE_UNAVAILABLE:
2539 fprintf(f, "Protection Storage Unavailable");
2540 break;
2541
2542 case KMIP_REASON_PKCS11_CODEC_ERROR:
2543 fprintf(f, "PKCS#11 Codec Error");
2544 break;
2545
2546 case KMIP_REASON_PKCS11_INVALID_FUNCTION:
2547 fprintf(f, "PKCS#11 Invalid Function");
2548 break;
2549
2550 case KMIP_REASON_PKCS11_INVALID_INTERFACE:
2551 fprintf(f, "PKCS#11 Invalid Interface");
2552 break;
2553
2554 case KMIP_REASON_PRIVATE_PROTECTION_STORAGE_UNAVAILABLE:
2555 fprintf(f, "Private Protection Storage Unavailable");
2556 break;
2557
2558 case KMIP_REASON_PUBLIC_PROTECTION_STORAGE_UNAVAILABLE:
2559 fprintf(f, "Public Protection Storage Unavailable");
2560 break;
2561
2562 default:
2563 fprintf(f, "Unknown");
2564 break;
2565 };
2566 }
2567
2568 void
2569 kmip_print_object_type_enum(FILE *f, enum object_type value)
2570 {
2571 if(value == 0)
2572 {
2573 fprintf(f, "-");
2574 return;
2575 }
2576
2577 switch(value)
2578 {
2579 case KMIP_OBJTYPE_CERTIFICATE:
2580 fprintf(f, "Certificate");
2581 break;
2582
2583 case KMIP_OBJTYPE_SYMMETRIC_KEY:
2584 fprintf(f, "Symmetric Key");
2585 break;
2586
2587 case KMIP_OBJTYPE_PUBLIC_KEY:
2588 fprintf(f, "Public Key");
2589 break;
2590
2591 case KMIP_OBJTYPE_PRIVATE_KEY:
2592 fprintf(f, "Private Key");
2593 break;
2594
2595 case KMIP_OBJTYPE_SPLIT_KEY:
2596 fprintf(f, "Split Key");
2597 break;
2598
2599 case KMIP_OBJTYPE_TEMPLATE:
2600 fprintf(f, "Template");
2601 break;
2602
2603 case KMIP_OBJTYPE_SECRET_DATA:
2604 fprintf(f, "Secret Data");
2605 break;
2606
2607 case KMIP_OBJTYPE_OPAQUE_OBJECT:
2608 fprintf(f, "Opaque Object");
2609 break;
2610
2611 case KMIP_OBJTYPE_PGP_KEY:
2612 fprintf(f, "PGP Key");
2613 break;
2614
2615 case KMIP_OBJTYPE_CERTIFICATE_REQUEST:
2616 fprintf(f, "Certificate Request");
2617 break;
2618
2619 default:
2620 fprintf(f, "Unknown");
2621 break;
2622 };
2623 }
2624
2625 void
2626 kmip_print_key_format_type_enum(FILE *f, enum key_format_type value)
2627 {
2628 if(value == 0)
2629 {
2630 fprintf(f, "-");
2631 return;
2632 }
2633
2634 switch(value)
2635 {
2636 case KMIP_KEYFORMAT_RAW:
2637 fprintf(f, "Raw");
2638 break;
2639
2640 case KMIP_KEYFORMAT_OPAQUE:
2641 fprintf(f, "Opaque");
2642 break;
2643
2644 case KMIP_KEYFORMAT_PKCS1:
2645 fprintf(f, "PKCS1");
2646 break;
2647
2648 case KMIP_KEYFORMAT_PKCS8:
2649 fprintf(f, "PKCS8");
2650 break;
2651
2652 case KMIP_KEYFORMAT_X509:
2653 fprintf(f, "X509");
2654 break;
2655
2656 case KMIP_KEYFORMAT_EC_PRIVATE_KEY:
2657 fprintf(f, "EC Private Key");
2658 break;
2659
2660 case KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY:
2661 fprintf(f, "Transparent Symmetric Key");
2662 break;
2663
2664 case KMIP_KEYFORMAT_TRANS_DSA_PRIVATE_KEY:
2665 fprintf(f, "Transparent DSA Private Key");
2666 break;
2667
2668 case KMIP_KEYFORMAT_TRANS_DSA_PUBLIC_KEY:
2669 fprintf(f, "Transparent DSA Public Key");
2670 break;
2671
2672 case KMIP_KEYFORMAT_TRANS_RSA_PRIVATE_KEY:
2673 fprintf(f, "Transparent RSA Private Key");
2674 break;
2675
2676 case KMIP_KEYFORMAT_TRANS_RSA_PUBLIC_KEY:
2677 fprintf(f, "Transparent RSA Public Key");
2678 break;
2679
2680 case KMIP_KEYFORMAT_TRANS_DH_PRIVATE_KEY:
2681 fprintf(f, "Transparent DH Private Key");
2682 break;
2683
2684 case KMIP_KEYFORMAT_TRANS_DH_PUBLIC_KEY:
2685 fprintf(f, "Transparent DH Public Key");
2686 break;
2687
2688 case KMIP_KEYFORMAT_TRANS_ECDSA_PRIVATE_KEY:
2689 fprintf(f, "Transparent ECDSA Private Key");
2690 break;
2691
2692 case KMIP_KEYFORMAT_TRANS_ECDSA_PUBLIC_KEY:
2693 fprintf(f, "Transparent ECDSA Public Key");
2694 break;
2695
2696 case KMIP_KEYFORMAT_TRANS_ECDH_PRIVATE_KEY:
2697 fprintf(f, "Transparent ECDH Private Key");
2698 break;
2699
2700 case KMIP_KEYFORMAT_TRANS_ECDH_PUBLIC_KEY:
2701 fprintf(f, "Transparent ECDH Public Key");
2702 break;
2703
2704 case KMIP_KEYFORMAT_TRANS_ECMQV_PRIVATE_KEY:
2705 fprintf(f, "Transparent ECMQV Private Key");
2706 break;
2707
2708 case KMIP_KEYFORMAT_TRANS_ECMQV_PUBLIC_KEY:
2709 fprintf(f, "Transparent ECMQV Public Key");
2710 break;
2711
2712 case KMIP_KEYFORMAT_TRANS_EC_PRIVATE_KEY:
2713 fprintf(f, "Transparent EC Private Key");
2714 break;
2715
2716 case KMIP_KEYFORMAT_TRANS_EC_PUBLIC_KEY:
2717 fprintf(f, "Transparent EC Public Key");
2718 break;
2719
2720 case KMIP_KEYFORMAT_PKCS12:
2721 fprintf(f, "PKCS#12");
2722 break;
2723
2724 case KMIP_KEYFORMAT_PKCS10:
2725 fprintf(f, "PKCS#10");
2726 break;
2727
2728 default:
2729 fprintf(f, "Unknown");
2730 break;
2731 };
2732 }
2733
2734 void
2735 kmip_print_key_compression_type_enum(FILE *f, enum key_compression_type value)
2736 {
2737 if(value == 0)
2738 {
2739 fprintf(f, "-");
2740 return;
2741 }
2742
2743 switch(value)
2744 {
2745 case KMIP_KEYCOMP_EC_PUB_UNCOMPRESSED:
2746 fprintf(f, "EC Public Key Type Uncompressed");
2747 break;
2748
2749 case KMIP_KEYCOMP_EC_PUB_X962_COMPRESSED_PRIME:
2750 fprintf(f, "EC Public Key Type X9.62 Compressed Prime");
2751 break;
2752
2753 case KMIP_KEYCOMP_EC_PUB_X962_COMPRESSED_CHAR2:
2754 fprintf(f, "EC Public Key Type X9.62 Compressed Char2");
2755 break;
2756
2757 case KMIP_KEYCOMP_EC_PUB_X962_HYBRID:
2758 fprintf(f, "EC Public Key Type X9.62 Hybrid");
2759 break;
2760
2761 default:
2762 fprintf(f, "Unknown");
2763 break;
2764 };
2765 }
2766
2767 void
2768 kmip_print_cryptographic_algorithm_enum(FILE *f, enum cryptographic_algorithm value)
2769 {
2770 if(value == 0)
2771 {
2772 fprintf(f, "-");
2773 return;
2774 }
2775
2776 switch(value)
2777 {
2778 case KMIP_CRYPTOALG_DES:
2779 fprintf(f, "DES");
2780 break;
2781
2782 case KMIP_CRYPTOALG_TRIPLE_DES:
2783 fprintf(f, "3DES");
2784 break;
2785
2786 case KMIP_CRYPTOALG_AES:
2787 fprintf(f, "AES");
2788 break;
2789
2790 case KMIP_CRYPTOALG_RSA:
2791 fprintf(f, "RSA");
2792 break;
2793
2794 case KMIP_CRYPTOALG_DSA:
2795 fprintf(f, "DSA");
2796 break;
2797
2798 case KMIP_CRYPTOALG_ECDSA:
2799 fprintf(f, "ECDSA");
2800 break;
2801
2802 case KMIP_CRYPTOALG_HMAC_SHA1:
2803 fprintf(f, "SHA1");
2804 break;
2805
2806 case KMIP_CRYPTOALG_HMAC_SHA224:
2807 fprintf(f, "SHA224");
2808 break;
2809
2810 case KMIP_CRYPTOALG_HMAC_SHA256:
2811 fprintf(f, "SHA256");
2812 break;
2813
2814 case KMIP_CRYPTOALG_HMAC_SHA384:
2815 fprintf(f, "SHA384");
2816 break;
2817
2818 case KMIP_CRYPTOALG_HMAC_SHA512:
2819 fprintf(f, "SHA512");
2820 break;
2821
2822 case KMIP_CRYPTOALG_HMAC_MD5:
2823 fprintf(f, "MD5");
2824 break;
2825
2826 case KMIP_CRYPTOALG_DH:
2827 fprintf(f, "DH");
2828 break;
2829
2830 case KMIP_CRYPTOALG_ECDH:
2831 fprintf(f, "ECDH");
2832 break;
2833
2834 case KMIP_CRYPTOALG_ECMQV:
2835 fprintf(f, "ECMQV");
2836 break;
2837
2838 case KMIP_CRYPTOALG_BLOWFISH:
2839 fprintf(f, "Blowfish");
2840 break;
2841
2842 case KMIP_CRYPTOALG_CAMELLIA:
2843 fprintf(f, "Camellia");
2844 break;
2845
2846 case KMIP_CRYPTOALG_CAST5:
2847 fprintf(f, "CAST5");
2848 break;
2849
2850 case KMIP_CRYPTOALG_IDEA:
2851 fprintf(f, "IDEA");
2852 break;
2853
2854 case KMIP_CRYPTOALG_MARS:
2855 fprintf(f, "MARS");
2856 break;
2857
2858 case KMIP_CRYPTOALG_RC2:
2859 fprintf(f, "RC2");
2860 break;
2861
2862 case KMIP_CRYPTOALG_RC4:
2863 fprintf(f, "RC4");
2864 break;
2865
2866 case KMIP_CRYPTOALG_RC5:
2867 fprintf(f, "RC5");
2868 break;
2869
2870 case KMIP_CRYPTOALG_SKIPJACK:
2871 fprintf(f, "Skipjack");
2872 break;
2873
2874 case KMIP_CRYPTOALG_TWOFISH:
2875 fprintf(f, "Twofish");
2876 break;
2877
2878 case KMIP_CRYPTOALG_EC:
2879 fprintf(f, "EC");
2880 break;
2881
2882 case KMIP_CRYPTOALG_ONE_TIME_PAD:
2883 fprintf(f, "One Time Pad");
2884 break;
2885
2886 case KMIP_CRYPTOALG_CHACHA20:
2887 fprintf(f, "ChaCha20");
2888 break;
2889
2890 case KMIP_CRYPTOALG_POLY1305:
2891 fprintf(f, "Poly1305");
2892 break;
2893
2894 case KMIP_CRYPTOALG_CHACHA20_POLY1305:
2895 fprintf(f, "ChaCha20 Poly1305");
2896 break;
2897
2898 case KMIP_CRYPTOALG_SHA3_224:
2899 fprintf(f, "SHA3-224");
2900 break;
2901
2902 case KMIP_CRYPTOALG_SHA3_256:
2903 fprintf(f, "SHA3-256");
2904 break;
2905
2906 case KMIP_CRYPTOALG_SHA3_384:
2907 fprintf(f, "SHA3-384");
2908 break;
2909
2910 case KMIP_CRYPTOALG_SHA3_512:
2911 fprintf(f, "SHA3-512");
2912 break;
2913
2914 case KMIP_CRYPTOALG_HMAC_SHA3_224:
2915 fprintf(f, "HMAC SHA3-224");
2916 break;
2917
2918 case KMIP_CRYPTOALG_HMAC_SHA3_256:
2919 fprintf(f, "HMAC SHA3-256");
2920 break;
2921
2922 case KMIP_CRYPTOALG_HMAC_SHA3_384:
2923 fprintf(f, "HMAC SHA3-384");
2924 break;
2925
2926 case KMIP_CRYPTOALG_HMAC_SHA3_512:
2927 fprintf(f, "HMAC SHA3-512");
2928 break;
2929
2930 case KMIP_CRYPTOALG_SHAKE_128:
2931 fprintf(f, "SHAKE-128");
2932 break;
2933
2934 case KMIP_CRYPTOALG_SHAKE_256:
2935 fprintf(f, "SHAKE-256");
2936 break;
2937
2938 case KMIP_CRYPTOALG_ARIA:
2939 fprintf(f, "ARIA");
2940 break;
2941
2942 case KMIP_CRYPTOALG_SEED:
2943 fprintf(f, "SEED");
2944 break;
2945
2946 case KMIP_CRYPTOALG_SM2:
2947 fprintf(f, "SM2");
2948 break;
2949
2950 case KMIP_CRYPTOALG_SM3:
2951 fprintf(f, "SM3");
2952 break;
2953
2954 case KMIP_CRYPTOALG_SM4:
2955 fprintf(f, "SM4");
2956 break;
2957
2958 case KMIP_CRYPTOALG_GOST_R_34_10_2012:
2959 fprintf(f, "GOST R 34.10-2012");
2960 break;
2961
2962 case KMIP_CRYPTOALG_GOST_R_34_11_2012:
2963 fprintf(f, "GOST R 34.11-2012");
2964 break;
2965
2966 case KMIP_CRYPTOALG_GOST_R_34_13_2015:
2967 fprintf(f, "GOST R 34.13-2015");
2968 break;
2969
2970 case KMIP_CRYPTOALG_GOST_28147_89:
2971 fprintf(f, "GOST 28147-89");
2972 break;
2973
2974 case KMIP_CRYPTOALG_XMSS:
2975 fprintf(f, "XMSS");
2976 break;
2977
2978 case KMIP_CRYPTOALG_SPHINCS_256:
2979 fprintf(f, "SPHINCS-256");
2980 break;
2981
2982 case KMIP_CRYPTOALG_MCELIECE:
2983 fprintf(f, "McEliece");
2984 break;
2985
2986 case KMIP_CRYPTOALG_MCELIECE_6960119:
2987 fprintf(f, "McEliece 6960119");
2988 break;
2989
2990 case KMIP_CRYPTOALG_MCELIECE_8192128:
2991 fprintf(f, "McEliece 8192128");
2992 break;
2993
2994 case KMIP_CRYPTOALG_ED25519:
2995 fprintf(f, "Ed25519");
2996 break;
2997
2998 case KMIP_CRYPTOALG_ED448:
2999 fprintf(f, "Ed448");
3000 break;
3001
3002 default:
3003 fprintf(f, "Unknown");
3004 break;
3005 };
3006 }
3007
3008 void
3009 kmip_print_name_type_enum(FILE *f, enum name_type value)
3010 {
3011 if(value == 0)
3012 {
3013 fprintf(f, "-");
3014 return;
3015 }
3016
3017 switch(value)
3018 {
3019 case KMIP_NAME_UNINTERPRETED_TEXT_STRING:
3020 fprintf(f, "Uninterpreted Text String");
3021 break;
3022
3023 case KMIP_NAME_URI:
3024 fprintf(f, "URI");
3025 break;
3026
3027 default:
3028 fprintf(f, "Unknown");
3029 break;
3030 };
3031 }
3032
3033 void
3034 kmip_print_attribute_type_enum(FILE *f, enum attribute_type value)
3035 {
3036 if((int)value == KMIP_UNSET)
3037 {
3038 fprintf(f, "-");
3039 return;
3040 }
3041
3042 switch(value)
3043 {
3044 case KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION:
3045 {
3046 fprintf(f, "Application Specific Information");
3047 }
3048 break;
3049
3050 case KMIP_ATTR_UNIQUE_IDENTIFIER:
3051 fprintf(f, "Unique Identifier");
3052 break;
3053
3054 case KMIP_ATTR_NAME:
3055 fprintf(f, "Name");
3056 break;
3057
3058 case KMIP_ATTR_OBJECT_TYPE:
3059 fprintf(f, "Object Type");
3060 break;
3061
3062 case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
3063 fprintf(f, "Cryptographic Algorithm");
3064 break;
3065
3066 case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
3067 fprintf(f, "Cryptographic Length");
3068 break;
3069
3070 case KMIP_ATTR_OPERATION_POLICY_NAME:
3071 fprintf(f, "Operation Policy Name");
3072 break;
3073
3074 case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
3075 fprintf(f, "Cryptographic Usage Mask");
3076 break;
3077
3078 case KMIP_ATTR_STATE:
3079 fprintf(f, "State");
3080 break;
3081
3082 case KMIP_ATTR_OBJECT_GROUP:
3083 {
3084 fprintf(f, "Object Group");
3085 }
3086 break;
3087
3088 case KMIP_ATTR_ACTIVATION_DATE:
3089 {
3090 fprintf(f, "Activation Date");
3091 } break;
3092
3093 case KMIP_ATTR_DEACTIVATION_DATE:
3094 {
3095 fprintf(f, "Deactivation Date");
3096 } break;
3097
3098 case KMIP_ATTR_PROCESS_START_DATE:
3099 {
3100 fprintf(f, "Process Start Date");
3101 } break;
3102
3103 case KMIP_ATTR_PROTECT_STOP_DATE:
3104 {
3105 fprintf(f, "Protect Stop Date");
3106 } break;
3107
3108 case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
3109 {
3110 fprintf(f, "Cryptographic Parameters");
3111 } break;
3112
3113 default:
3114 fprintf(f, "Unknown");
3115 break;
3116 };
3117 }
3118
3119 void
3120 kmip_print_state_enum(FILE *f, enum state value)
3121 {
3122 if(value == 0)
3123 {
3124 fprintf(f, "-");
3125 return;
3126 }
3127
3128 switch(value)
3129 {
3130 case KMIP_STATE_PRE_ACTIVE:
3131 fprintf(f, "Pre-Active");
3132 break;
3133
3134 case KMIP_STATE_ACTIVE:
3135 fprintf(f, "Active");
3136 break;
3137
3138 case KMIP_STATE_DEACTIVATED:
3139 fprintf(f, "Deactivated");
3140 break;
3141
3142 case KMIP_STATE_COMPROMISED:
3143 fprintf(f, "Compromised");
3144 break;
3145
3146 case KMIP_STATE_DESTROYED:
3147 fprintf(f, "Destroyed");
3148 break;
3149
3150 case KMIP_STATE_DESTROYED_COMPROMISED:
3151 fprintf(f, "Destroyed Compromised");
3152 break;
3153
3154 default:
3155 fprintf(f, "Unknown");
3156 break;
3157 };
3158 }
3159
3160 void
3161 kmip_print_block_cipher_mode_enum(FILE *f, enum block_cipher_mode value)
3162 {
3163 if(value == 0)
3164 {
3165 fprintf(f, "-");
3166 return;
3167 }
3168
3169 switch(value)
3170 {
3171 case KMIP_BLOCK_CBC:
3172 fprintf(f, "CBC");
3173 break;
3174
3175 case KMIP_BLOCK_ECB:
3176 fprintf(f, "ECB");
3177 break;
3178
3179 case KMIP_BLOCK_PCBC:
3180 fprintf(f, "PCBC");
3181 break;
3182
3183 case KMIP_BLOCK_CFB:
3184 fprintf(f, "CFB");
3185 break;
3186
3187 case KMIP_BLOCK_OFB:
3188 fprintf(f, "OFB");
3189 break;
3190
3191 case KMIP_BLOCK_CTR:
3192 fprintf(f, "CTR");
3193 break;
3194
3195 case KMIP_BLOCK_CMAC:
3196 fprintf(f, "CMAC");
3197 break;
3198
3199 case KMIP_BLOCK_CCM:
3200 fprintf(f, "CCM");
3201 break;
3202
3203 case KMIP_BLOCK_GCM:
3204 fprintf(f, "GCM");
3205 break;
3206
3207 case KMIP_BLOCK_CBC_MAC:
3208 fprintf(f, "CBC-MAC");
3209 break;
3210
3211 case KMIP_BLOCK_XTS:
3212 fprintf(f, "XTS");
3213 break;
3214
3215 case KMIP_BLOCK_AES_KEY_WRAP_PADDING:
3216 fprintf(f, "AESKeyWrapPadding");
3217 break;
3218
3219 case KMIP_BLOCK_NIST_KEY_WRAP:
3220 fprintf(f, "NISTKeyWrap");
3221 break;
3222
3223 case KMIP_BLOCK_X9102_AESKW:
3224 fprintf(f, "X9.102 AESKW");
3225 break;
3226
3227 case KMIP_BLOCK_X9102_TDKW:
3228 fprintf(f, "X9.102 TDKW");
3229 break;
3230
3231 case KMIP_BLOCK_X9102_AKW1:
3232 fprintf(f, "X9.102 AKW1");
3233 break;
3234
3235 case KMIP_BLOCK_X9102_AKW2:
3236 fprintf(f, "X9.102 AKW2");
3237 break;
3238
3239 case KMIP_BLOCK_AEAD:
3240 fprintf(f, "AEAD");
3241 break;
3242
3243 default:
3244 fprintf(f, "Unknown");
3245 break;
3246 };
3247 }
3248
3249 void
3250 kmip_print_padding_method_enum(FILE *f, enum padding_method value)
3251 {
3252 if(value == 0)
3253 {
3254 fprintf(f, "-");
3255 return;
3256 }
3257
3258 switch(value)
3259 {
3260 case KMIP_PAD_NONE:
3261 fprintf(f, "None");
3262 break;
3263
3264 case KMIP_PAD_OAEP:
3265 fprintf(f, "OAEP");
3266 break;
3267
3268 case KMIP_PAD_PKCS5:
3269 fprintf(f, "PKCS5");
3270 break;
3271
3272 case KMIP_PAD_SSL3:
3273 fprintf(f, "SSL3");
3274 break;
3275
3276 case KMIP_PAD_ZEROS:
3277 fprintf(f, "Zeros");
3278 break;
3279
3280 case KMIP_PAD_ANSI_X923:
3281 fprintf(f, "ANSI X9.23");
3282 break;
3283
3284 case KMIP_PAD_ISO_10126:
3285 fprintf(f, "ISO 10126");
3286 break;
3287
3288 case KMIP_PAD_PKCS1v15:
3289 fprintf(f, "PKCS1 v1.5");
3290 break;
3291
3292 case KMIP_PAD_X931:
3293 fprintf(f, "X9.31");
3294 break;
3295
3296 case KMIP_PAD_PSS:
3297 fprintf(f, "PSS");
3298 break;
3299
3300 default:
3301 fprintf(f, "Unknown");
3302 break;
3303 };
3304 }
3305
3306 void
3307 kmip_print_hashing_algorithm_enum(FILE *f, enum hashing_algorithm value)
3308 {
3309 if(value == 0)
3310 {
3311 fprintf(f, "-");
3312 return;
3313 }
3314
3315 switch(value)
3316 {
3317 case KMIP_HASH_MD2:
3318 fprintf(f, "MD2");
3319 break;
3320
3321 case KMIP_HASH_MD4:
3322 fprintf(f, "MD4");
3323 break;
3324
3325 case KMIP_HASH_MD5:
3326 fprintf(f, "MD5");
3327 break;
3328
3329 case KMIP_HASH_SHA1:
3330 fprintf(f, "SHA-1");
3331 break;
3332
3333 case KMIP_HASH_SHA224:
3334 fprintf(f, "SHA-224");
3335 break;
3336
3337 case KMIP_HASH_SHA256:
3338 fprintf(f, "SHA-256");
3339 break;
3340
3341 case KMIP_HASH_SHA384:
3342 fprintf(f, "SHA-384");
3343 break;
3344
3345 case KMIP_HASH_SHA512:
3346 fprintf(f, "SHA-512");
3347 break;
3348
3349 case KMIP_HASH_RIPEMD160:
3350 fprintf(f, "RIPEMD-160");
3351 break;
3352
3353 case KMIP_HASH_TIGER:
3354 fprintf(f, "Tiger");
3355 break;
3356
3357 case KMIP_HASH_WHIRLPOOL:
3358 fprintf(f, "Whirlpool");
3359 break;
3360
3361 case KMIP_HASH_SHA512_224:
3362 fprintf(f, "SHA-512/224");
3363 break;
3364
3365 case KMIP_HASH_SHA512_256:
3366 fprintf(f, "SHA-512/256");
3367 break;
3368
3369 case KMIP_HASH_SHA3_224:
3370 fprintf(f, "SHA-3-224");
3371 break;
3372
3373 case KMIP_HASH_SHA3_256:
3374 fprintf(f, "SHA-3-256");
3375 break;
3376
3377 case KMIP_HASH_SHA3_384:
3378 fprintf(f, "SHA-3-384");
3379 break;
3380
3381 case KMIP_HASH_SHA3_512:
3382 fprintf(f, "SHA-3-512");
3383 break;
3384
3385 default:
3386 fprintf(f, "Unknown");
3387 break;
3388 };
3389 }
3390
3391 void
3392 kmip_print_key_role_type_enum(FILE *f, enum key_role_type value)
3393 {
3394 if(value == 0)
3395 {
3396 fprintf(f, "-");
3397 return;
3398 }
3399
3400 switch(value)
3401 {
3402 case KMIP_ROLE_BDK:
3403 fprintf(f, "BDK");
3404 break;
3405
3406 case KMIP_ROLE_CVK:
3407 fprintf(f, "CVK");
3408 break;
3409
3410 case KMIP_ROLE_DEK:
3411 fprintf(f, "DEK");
3412 break;
3413
3414 case KMIP_ROLE_MKAC:
3415 fprintf(f, "MKAC");
3416 break;
3417
3418 case KMIP_ROLE_MKSMC:
3419 fprintf(f, "MKSMC");
3420 break;
3421
3422 case KMIP_ROLE_MKSMI:
3423 fprintf(f, "MKSMI");
3424 break;
3425
3426 case KMIP_ROLE_MKDAC:
3427 fprintf(f, "MKDAC");
3428 break;
3429
3430 case KMIP_ROLE_MKDN:
3431 fprintf(f, "MKDN");
3432 break;
3433
3434 case KMIP_ROLE_MKCP:
3435 fprintf(f, "MKCP");
3436 break;
3437
3438 case KMIP_ROLE_MKOTH:
3439 fprintf(f, "MKOTH");
3440 break;
3441
3442 case KMIP_ROLE_KEK:
3443 fprintf(f, "KEK");
3444 break;
3445
3446 case KMIP_ROLE_MAC16609:
3447 fprintf(f, "MAC16609");
3448 break;
3449
3450 case KMIP_ROLE_MAC97971:
3451 fprintf(f, "MAC97971");
3452 break;
3453
3454 case KMIP_ROLE_MAC97972:
3455 fprintf(f, "MAC97972");
3456 break;
3457
3458 case KMIP_ROLE_MAC97973:
3459 fprintf(f, "MAC97973");
3460 break;
3461
3462 case KMIP_ROLE_MAC97974:
3463 fprintf(f, "MAC97974");
3464 break;
3465
3466 case KMIP_ROLE_MAC97975:
3467 fprintf(f, "MAC97975");
3468 break;
3469
3470 case KMIP_ROLE_ZPK:
3471 fprintf(f, "ZPK");
3472 break;
3473
3474 case KMIP_ROLE_PVKIBM:
3475 fprintf(f, "PVKIBM");
3476 break;
3477
3478 case KMIP_ROLE_PVKPVV:
3479 fprintf(f, "PVKPVV");
3480 break;
3481
3482 case KMIP_ROLE_PVKOTH:
3483 fprintf(f, "PVKOTH");
3484 break;
3485
3486 case KMIP_ROLE_DUKPT:
3487 fprintf(f, "DUKPT");
3488 break;
3489
3490 case KMIP_ROLE_IV:
3491 fprintf(f, "IV");
3492 break;
3493
3494 case KMIP_ROLE_TRKBK:
3495 fprintf(f, "TRKBK");
3496 break;
3497
3498 default:
3499 fprintf(f, "Unknown");
3500 break;
3501 };
3502 }
3503
3504 void
3505 kmip_print_digital_signature_algorithm_enum(FILE *f, enum digital_signature_algorithm value)
3506 {
3507 if(value == 0)
3508 {
3509 fprintf(f, "-");
3510 return;
3511 }
3512
3513 switch(value)
3514 {
3515 case KMIP_DIGITAL_MD2_WITH_RSA:
3516 fprintf(f, "MD2 with RSA Encryption (PKCS#1 v1.5)");
3517 break;
3518
3519 case KMIP_DIGITAL_MD5_WITH_RSA:
3520 fprintf(f, "MD5 with RSA Encryption (PKCS#1 v1.5)");
3521 break;
3522
3523 case KMIP_DIGITAL_SHA1_WITH_RSA:
3524 fprintf(f, "SHA-1 with RSA Encryption (PKCS#1 v1.5)");
3525 break;
3526
3527 case KMIP_DIGITAL_SHA224_WITH_RSA:
3528 fprintf(f, "SHA-224 with RSA Encryption (PKCS#1 v1.5)");
3529 break;
3530
3531 case KMIP_DIGITAL_SHA256_WITH_RSA:
3532 fprintf(f, "SHA-256 with RSA Encryption (PKCS#1 v1.5)");
3533 break;
3534
3535 case KMIP_DIGITAL_SHA384_WITH_RSA:
3536 fprintf(f, "SHA-384 with RSA Encryption (PKCS#1 v1.5)");
3537 break;
3538
3539 case KMIP_DIGITAL_SHA512_WITH_RSA:
3540 fprintf(f, "SHA-512 with RSA Encryption (PKCS#1 v1.5)");
3541 break;
3542
3543 case KMIP_DIGITAL_RSASSA_PSS:
3544 fprintf(f, "RSASSA-PSS (PKCS#1 v2.1)");
3545 break;
3546
3547 case KMIP_DIGITAL_DSA_WITH_SHA1:
3548 fprintf(f, "DSA with SHA-1");
3549 break;
3550
3551 case KMIP_DIGITAL_DSA_WITH_SHA224:
3552 fprintf(f, "DSA with SHA224");
3553 break;
3554
3555 case KMIP_DIGITAL_DSA_WITH_SHA256:
3556 fprintf(f, "DSA with SHA256");
3557 break;
3558
3559 case KMIP_DIGITAL_ECDSA_WITH_SHA1:
3560 fprintf(f, "ECDSA with SHA-1");
3561 break;
3562
3563 case KMIP_DIGITAL_ECDSA_WITH_SHA224:
3564 fprintf(f, "ECDSA with SHA224");
3565 break;
3566
3567 case KMIP_DIGITAL_ECDSA_WITH_SHA256:
3568 fprintf(f, "ECDSA with SHA256");
3569 break;
3570
3571 case KMIP_DIGITAL_ECDSA_WITH_SHA384:
3572 fprintf(f, "ECDSA with SHA384");
3573 break;
3574
3575 case KMIP_DIGITAL_ECDSA_WITH_SHA512:
3576 fprintf(f, "ECDSA with SHA512");
3577 break;
3578
3579 case KMIP_DIGITAL_SHA3_256_WITH_RSA:
3580 fprintf(f, "SHA3-256 with RSA Encryption");
3581 break;
3582
3583 case KMIP_DIGITAL_SHA3_384_WITH_RSA:
3584 fprintf(f, "SHA3-384 with RSA Encryption");
3585 break;
3586
3587 case KMIP_DIGITAL_SHA3_512_WITH_RSA:
3588 fprintf(f, "SHA3-512 with RSA Encryption");
3589 break;
3590
3591 default:
3592 fprintf(f, "Unknown");
3593 break;
3594 };
3595 }
3596
3597 void
3598 kmip_print_mask_generator_enum(FILE *f, enum mask_generator value)
3599 {
3600 if(value == 0)
3601 {
3602 fprintf(f, "-");
3603 return;
3604 }
3605
3606 switch(value)
3607 {
3608 case KMIP_MASKGEN_MGF1:
3609 fprintf(f, "MGF1");
3610 break;
3611
3612 default:
3613 fprintf(f, "Unknown");
3614 break;
3615 };
3616 }
3617
3618 void
3619 kmip_print_wrapping_method_enum(FILE *f, enum wrapping_method value)
3620 {
3621 if(value == 0)
3622 {
3623 fprintf(f, "-");
3624 return;
3625 }
3626
3627 switch(value)
3628 {
3629 case KMIP_WRAP_ENCRYPT:
3630 fprintf(f, "Encrypt");
3631 break;
3632
3633 case KMIP_WRAP_MAC_SIGN:
3634 fprintf(f, "MAC/sign");
3635 break;
3636
3637 case KMIP_WRAP_ENCRYPT_MAC_SIGN:
3638 fprintf(f, "Encrypt then MAC/sign");
3639 break;
3640
3641 case KMIP_WRAP_MAC_SIGN_ENCRYPT:
3642 fprintf(f, "MAC/sign then encrypt");
3643 break;
3644
3645 case KMIP_WRAP_TR31:
3646 fprintf(f, "TR-31");
3647 break;
3648
3649 default:
3650 fprintf(f, "Unknown");
3651 break;
3652 };
3653 }
3654
3655 void
3656 kmip_print_encoding_option_enum(FILE *f, enum encoding_option value)
3657 {
3658 if(value == 0)
3659 {
3660 fprintf(f, "-");
3661 return;
3662 }
3663
3664 switch(value)
3665 {
3666 case KMIP_ENCODE_NO_ENCODING:
3667 fprintf(f, "No Encoding");
3668 break;
3669
3670 case KMIP_ENCODE_TTLV_ENCODING:
3671 fprintf(f, "TTLV Encoding");
3672 break;
3673
3674 default:
3675 fprintf(f, "Unknown");
3676 break;
3677 };
3678 }
3679
3680 void
3681 kmip_print_key_wrap_type_enum(FILE *f, enum key_wrap_type value)
3682 {
3683 if(value == 0)
3684 {
3685 fprintf(f, "-");
3686 return;
3687 }
3688
3689 switch(value)
3690 {
3691 case KMIP_WRAPTYPE_NOT_WRAPPED:
3692 fprintf(f, "Not Wrapped");
3693 break;
3694
3695 case KMIP_WRAPTYPE_AS_REGISTERED:
3696 fprintf(f, "As Registered");
3697 break;
3698
3699 default:
3700 fprintf(f, "Unknown");
3701 break;
3702 };
3703 }
3704
3705 void
3706 kmip_print_credential_type_enum(FILE *f, enum credential_type value)
3707 {
3708 if(value == 0)
3709 {
3710 fprintf(f, "-");
3711 return;
3712 }
3713
3714 switch(value)
3715 {
3716 case KMIP_CRED_USERNAME_AND_PASSWORD:
3717 fprintf(f, "Username and Password");
3718 break;
3719
3720 case KMIP_CRED_DEVICE:
3721 fprintf(f, "Device");
3722 break;
3723
3724 case KMIP_CRED_ATTESTATION:
3725 fprintf(f, "Attestation");
3726 break;
3727
3728 case KMIP_CRED_ONE_TIME_PASSWORD:
3729 fprintf(f, "One Time Password");
3730 break;
3731
3732 case KMIP_CRED_HASHED_PASSWORD:
3733 fprintf(f, "Hashed Password");
3734 break;
3735
3736 case KMIP_CRED_TICKET:
3737 fprintf(f, "Ticket");
3738 break;
3739
3740 default:
3741 fprintf(f, "Unknown");
3742 break;
3743 };
3744 }
3745
3746 void
3747 kmip_print_cryptographic_usage_mask_enums(FILE *f, int indent, int32 value)
3748 {
3749 fprintf(f, "\n");
3750
3751 if((value & KMIP_CRYPTOMASK_SIGN) == KMIP_CRYPTOMASK_SIGN)
3752 {
3753 fprintf(f, "%*sSign\n", indent, "");
3754 }
3755
3756 if((value & KMIP_CRYPTOMASK_VERIFY) == KMIP_CRYPTOMASK_VERIFY)
3757 {
3758 fprintf(f, "%*sVerify\n", indent, "");
3759 }
3760
3761 if((value & KMIP_CRYPTOMASK_ENCRYPT) == KMIP_CRYPTOMASK_ENCRYPT)
3762 {
3763 fprintf(f, "%*sEncrypt\n", indent, "");
3764 }
3765
3766 if((value & KMIP_CRYPTOMASK_DECRYPT) == KMIP_CRYPTOMASK_DECRYPT)
3767 {
3768 fprintf(f, "%*sDecrypt\n", indent, "");
3769 }
3770
3771 if((value & KMIP_CRYPTOMASK_WRAP_KEY) == KMIP_CRYPTOMASK_WRAP_KEY)
3772 {
3773 fprintf(f, "%*sWrap Key\n", indent, "");
3774 }
3775
3776 if((value & KMIP_CRYPTOMASK_UNWRAP_KEY) == KMIP_CRYPTOMASK_UNWRAP_KEY)
3777 {
3778 fprintf(f, "%*sUnwrap Key\n", indent, "");
3779 }
3780
3781 if((value & KMIP_CRYPTOMASK_EXPORT) == KMIP_CRYPTOMASK_EXPORT)
3782 {
3783 fprintf(f, "%*sExport\n", indent, "");
3784 }
3785
3786 if((value & KMIP_CRYPTOMASK_MAC_GENERATE) == KMIP_CRYPTOMASK_MAC_GENERATE)
3787 {
3788 fprintf(f, "%*sMAC Generate\n", indent, "");
3789 }
3790
3791 if((value & KMIP_CRYPTOMASK_MAC_VERIFY) == KMIP_CRYPTOMASK_MAC_VERIFY)
3792 {
3793 fprintf(f, "%*sMAC Verify\n", indent, "");
3794 }
3795
3796 if((value & KMIP_CRYPTOMASK_DERIVE_KEY) == KMIP_CRYPTOMASK_DERIVE_KEY)
3797 {
3798 fprintf(f, "%*sDerive Key\n", indent, "");
3799 }
3800
3801 if((value & KMIP_CRYPTOMASK_CONTENT_COMMITMENT) == KMIP_CRYPTOMASK_CONTENT_COMMITMENT)
3802 {
3803 fprintf(f, "%*sContent Commitment\n", indent, "");
3804 }
3805
3806 if((value & KMIP_CRYPTOMASK_KEY_AGREEMENT) == KMIP_CRYPTOMASK_KEY_AGREEMENT)
3807 {
3808 fprintf(f, "%*sKey Agreement\n", indent, "");
3809 }
3810
3811 if((value & KMIP_CRYPTOMASK_CERTIFICATE_SIGN) == KMIP_CRYPTOMASK_CERTIFICATE_SIGN)
3812 {
3813 fprintf(f, "%*sCertificate Sign\n", indent, "");
3814 }
3815
3816 if((value & KMIP_CRYPTOMASK_CRL_SIGN) == KMIP_CRYPTOMASK_CRL_SIGN)
3817 {
3818 fprintf(f, "%*sCRL Sign\n", indent, "");
3819 }
3820
3821 if((value & KMIP_CRYPTOMASK_GENERATE_CRYPTOGRAM) == KMIP_CRYPTOMASK_GENERATE_CRYPTOGRAM)
3822 {
3823 fprintf(f, "%*sGenerate Cryptogram\n", indent, "");
3824 }
3825
3826 if((value & KMIP_CRYPTOMASK_VALIDATE_CRYPTOGRAM) == KMIP_CRYPTOMASK_VALIDATE_CRYPTOGRAM)
3827 {
3828 fprintf(f, "%*sValidate Cryptogram\n", indent, "");
3829 }
3830
3831 if((value & KMIP_CRYPTOMASK_TRANSLATE_ENCRYPT) == KMIP_CRYPTOMASK_TRANSLATE_ENCRYPT)
3832 {
3833 fprintf(f, "%*sTranslate Encrypt\n", indent, "");
3834 }
3835
3836 if((value & KMIP_CRYPTOMASK_TRANSLATE_DECRYPT) == KMIP_CRYPTOMASK_TRANSLATE_DECRYPT)
3837 {
3838 fprintf(f, "%*sTranslate Decrypt\n", indent, "");
3839 }
3840
3841 if((value & KMIP_CRYPTOMASK_TRANSLATE_WRAP) == KMIP_CRYPTOMASK_TRANSLATE_WRAP)
3842 {
3843 fprintf(f, "%*sTranslate Wrap\n", indent, "");
3844 }
3845
3846 if((value & KMIP_CRYPTOMASK_TRANSLATE_UNWRAP) == KMIP_CRYPTOMASK_TRANSLATE_UNWRAP)
3847 {
3848 fprintf(f, "%*sTranslate Unwrap\n", indent, "");
3849 }
3850
3851 if((value & KMIP_CRYPTOMASK_AUTHENTICATE) == KMIP_CRYPTOMASK_AUTHENTICATE)
3852 {
3853 fprintf(f, "%*sAuthenticate\n", indent, "");
3854 }
3855
3856 if((value & KMIP_CRYPTOMASK_UNRESTRICTED) == KMIP_CRYPTOMASK_UNRESTRICTED)
3857 {
3858 fprintf(f, "%*sUnrestricted\n", indent, "");
3859 }
3860
3861 if((value & KMIP_CRYPTOMASK_FPE_ENCRYPT) == KMIP_CRYPTOMASK_FPE_ENCRYPT)
3862 {
3863 fprintf(f, "%*sFPE Encrypt\n", indent, "");
3864 }
3865
3866 if((value & KMIP_CRYPTOMASK_FPE_DECRYPT) == KMIP_CRYPTOMASK_FPE_DECRYPT)
3867 {
3868 fprintf(f, "%*sFPE Decrypt\n", indent, "");
3869 }
3870 }
3871
3872 void
3873 kmip_print_protection_storage_mask_enum(FILE *f, int indent, int32 value)
3874 {
3875 fprintf(f, "\n");
3876
3877 if((value & KMIP_PROTECT_SOFTWARE) == KMIP_PROTECT_SOFTWARE)
3878 {
3879 fprintf(f, "%*sSoftware\n", indent, "");
3880 }
3881
3882 if((value & KMIP_PROTECT_HARDWARE) == KMIP_PROTECT_HARDWARE)
3883 {
3884 fprintf(f, "%*sHardware\n", indent, "");
3885 }
3886
3887 if((value & KMIP_PROTECT_ON_PROCESSOR) == KMIP_PROTECT_ON_PROCESSOR)
3888 {
3889 fprintf(f, "%*sOn Processor\n", indent, "");
3890 }
3891
3892 if((value & KMIP_PROTECT_ON_SYSTEM) == KMIP_PROTECT_ON_SYSTEM)
3893 {
3894 fprintf(f, "%*sOn System\n", indent, "");
3895 }
3896
3897 if((value & KMIP_PROTECT_OFF_SYSTEM) == KMIP_PROTECT_OFF_SYSTEM)
3898 {
3899 fprintf(f, "%*sOff System\n", indent, "");
3900 }
3901
3902 if((value & KMIP_PROTECT_HYPERVISOR) == KMIP_PROTECT_HYPERVISOR)
3903 {
3904 fprintf(f, "%*sHypervisor\n", indent, "");
3905 }
3906
3907 if((value & KMIP_PROTECT_OPERATING_SYSTEM) == KMIP_PROTECT_OPERATING_SYSTEM)
3908 {
3909 fprintf(f, "%*sOperating System\n", indent, "");
3910 }
3911
3912 if((value & KMIP_PROTECT_CONTAINER) == KMIP_PROTECT_CONTAINER)
3913 {
3914 fprintf(f, "%*sContainer\n", indent, "");
3915 }
3916
3917 if((value & KMIP_PROTECT_ON_PREMISES) == KMIP_PROTECT_ON_PREMISES)
3918 {
3919 fprintf(f, "%*sOn Premises\n", indent, "");
3920 }
3921
3922 if((value & KMIP_PROTECT_OFF_PREMISES) == KMIP_PROTECT_OFF_PREMISES)
3923 {
3924 fprintf(f, "%*sOff Premises\n", indent, "");
3925 }
3926
3927 if((value & KMIP_PROTECT_SELF_MANAGED) == KMIP_PROTECT_SELF_MANAGED)
3928 {
3929 fprintf(f, "%*sSelf Managed\n", indent, "");
3930 }
3931
3932 if((value & KMIP_PROTECT_OUTSOURCED) == KMIP_PROTECT_OUTSOURCED)
3933 {
3934 fprintf(f, "%*sOutsourced\n", indent, "");
3935 }
3936
3937 if((value & KMIP_PROTECT_VALIDATED) == KMIP_PROTECT_VALIDATED)
3938 {
3939 fprintf(f, "%*sValidated\n", indent, "");
3940 }
3941
3942 if((value & KMIP_PROTECT_SAME_JURISDICTION) == KMIP_PROTECT_SAME_JURISDICTION)
3943 {
3944 fprintf(f, "%*sSame Jurisdiction\n", indent, "");
3945 }
3946 }
3947
3948 void
3949 kmip_print_protection_storage_masks(FILE *f, int indent, ProtectionStorageMasks *value)
3950 {
3951 fprintf(f, "%*sProtection Storage Masks @ %p\n", indent, "", (void *)value);
3952
3953 if(value != NULL &&
3954 value->masks != NULL)
3955 {
3956 fprintf(f, "%*sMasks: %zu\n", indent + 2, "", value->masks->size);
3957 LinkedListItem *curr = value->masks->head;
3958 size_t count = 1;
3959 while(curr != NULL)
3960 {
3961 fprintf(f, "%*sMask: %zu", indent + 4, "", count);
3962 int32 mask = *(int32 *)curr->data;
3963 kmip_print_protection_storage_mask_enum(f, indent + 6, mask);
3964
3965 curr = curr->next;
3966 count++;
3967 }
3968 }
3969 }
3970
3971 void
3972 kmip_print_integer(FILE *f, int32 value)
3973 {
3974 switch(value)
3975 {
3976 case KMIP_UNSET:
3977 fprintf(f, "-");
3978 break;
3979
3980 default:
3981 fprintf(f, "%d", value);
3982 break;
3983 };
3984 }
3985
3986 void
3987 kmip_print_bool(FILE *f, int32 value)
3988 {
3989 switch(value)
3990 {
3991 case KMIP_TRUE:
3992 fprintf(f, "True");
3993 break;
3994
3995 case KMIP_FALSE:
3996 fprintf(f, "False");
3997 break;
3998
3999 default:
4000 fprintf(f, "-");
4001 break;
4002 };
4003 }
4004
4005 void
4006 kmip_print_text_string(FILE *f, int indent, const char *name, TextString *value)
4007 {
4008 fprintf(f, "%*s%s @ %p\n", indent, "", name, (void *)value);
4009
4010 if(value != NULL)
4011 {
4012 fprintf(f, "%*sValue: %.*s\n", indent + 2, "", (int)value->size, value->value);
4013 }
4014
4015 return;
4016 }
4017
4018 void
4019 kmip_print_byte_string(FILE *f, int indent, const char *name, ByteString *value)
4020 {
4021 fprintf(f, "%*s%s @ %p\n", indent, "", name, (void *)value);
4022
4023 if(value != NULL)
4024 {
4025 fprintf(f, "%*sValue:", indent + 2, "");
4026 for(size_t i = 0; i < value->size; i++)
4027 {
4028 if(i % 16 == 0)
4029 {
4030 fprintf(f, "\n%*s0x", indent + 4, "");
4031 }
4032 fprintf(f, "%02X", value->value[i]);
4033 }
4034 fprintf(f, "\n");
4035 }
4036
4037 return;
4038 }
4039
4040 void
4041 kmip_print_date_time(FILE *f, int64 value)
4042 {
4043 if(value <= KMIP_UNSET)
4044 {
4045 fprintf(f, "-");
4046 }
4047 else
4048 {
4049 /* NOTE: This cast is only problematic if the current year is 2038+
4050 * AND time_t is equivalent to an int32 data type. If these conditions
4051 * are true, the cast will overflow and the time value will appear to
4052 * be set in 1901+.
4053 *
4054 * No system should be using 32-bit time in 2038. If this impacts you,
4055 * upgrade your system.
4056 */
4057 time_t t = (time_t)value;
4058
4059 /* NOTE: The data pointed to by utc_time may change if gmtime is
4060 * called again before utc_time is used.
4061 */
4062 struct tm *utc_time = gmtime(&t);
4063 fprintf(f, "%s", asctime(utc_time));
4064 }
4065 return;
4066 }
4067
4068 void
4069 kmip_print_protocol_version(FILE *f, int indent, ProtocolVersion *value)
4070 {
4071 fprintf(f, "%*sProtocol Version @ %p\n", indent, "", (void *)value);
4072
4073 if(value != NULL)
4074 {
4075 fprintf(f, "%*sMajor: %d\n", indent + 2, "", value->major);
4076 fprintf(f, "%*sMinor: %d\n", indent + 2, "", value->minor);
4077 }
4078
4079 return;
4080 }
4081
4082 void
4083 kmip_print_name(FILE *f, int indent, Name *value)
4084 {
4085 fprintf(f, "%*sName @ %p\n", indent, "", (void *)value);
4086
4087 if(value != NULL)
4088 {
4089 kmip_print_text_string(f, indent + 2, "Name Value", value->value);
4090
4091 fprintf(f, "%*sName Type: ", indent + 2, "");
4092 kmip_print_name_type_enum(f, value->type);
4093 fprintf(f, "\n");
4094 }
4095 }
4096
4097 void
4098 kmip_print_nonce(FILE *f, int indent, Nonce *value)
4099 {
4100 fprintf(f, "%*sNonce @ %p\n", indent, "", (void *)value);
4101
4102 if(value != NULL)
4103 {
4104 kmip_print_byte_string(f, indent + 2, "Nonce ID", value->nonce_id);
4105 kmip_print_byte_string(f, indent + 2, "Nonce Value", value->nonce_value);
4106 }
4107
4108 return;
4109 }
4110
4111 void
4112 kmip_print_application_specific_information(FILE *f, int indent, ApplicationSpecificInformation *value)
4113 {
4114 fprintf(f, "%*sApplication Specific Information @ %p\n", indent, "", (void *)value);
4115
4116 if(value != NULL)
4117 {
4118 kmip_print_text_string(f, indent + 2, "Application Namespace", value->application_namespace);
4119 kmip_print_text_string(f, indent + 2, "Application Data", value->application_data);
4120 }
4121 }
4122
4123 void
4124 kmip_print_cryptographic_parameters(FILE *f, int indent, CryptographicParameters *value)
4125 {
4126 fprintf(f, "%*sCryptographic Parameters @ %p\n", indent, "", (void *)value);
4127
4128 if(value != NULL)
4129 {
4130 fprintf(f, "%*sBlock Cipher Mode: ", indent + 2, "");
4131 kmip_print_block_cipher_mode_enum(f, value->block_cipher_mode);
4132 fprintf(f, "\n");
4133
4134 fprintf(f, "%*sPadding Method: ", indent + 2, "");
4135 kmip_print_padding_method_enum(f, value->padding_method);
4136 fprintf(f, "\n");
4137
4138 fprintf(f, "%*sHashing Algorithm: ", indent + 2, "");
4139 kmip_print_hashing_algorithm_enum(f, value->hashing_algorithm);
4140 fprintf(f, "\n");
4141
4142 fprintf(f, "%*sKey Role Type: ", indent + 2, "");
4143 kmip_print_key_role_type_enum(f, value->key_role_type);
4144 fprintf(f, "\n");
4145
4146 fprintf(f, "%*sDigital Signature Algorithm: ", indent + 2, "");
4147 kmip_print_digital_signature_algorithm_enum(f, value->digital_signature_algorithm);
4148 fprintf(f, "\n");
4149
4150 fprintf(f, "%*sCryptographic Algorithm: ", indent + 2, "");
4151 kmip_print_cryptographic_algorithm_enum(f, value->cryptographic_algorithm);
4152 fprintf(f, "\n");
4153
4154 fprintf(f, "%*sRandom IV: ", indent + 2, "");
4155 kmip_print_bool(f, value->random_iv);
4156 fprintf(f, "\n");
4157
4158 fprintf(f, "%*sIV Length: ", indent + 2, "");
4159 kmip_print_integer(f, value->iv_length);
4160 fprintf(f, "\n");
4161
4162 fprintf(f, "%*sTag Length: ", indent + 2, "");
4163 kmip_print_integer(f, value->tag_length);
4164 fprintf(f, "\n");
4165
4166 fprintf(f, "%*sFixed Field Length: ", indent + 2, "");
4167 kmip_print_integer(f, value->fixed_field_length);
4168 fprintf(f, "\n");
4169
4170 fprintf(f, "%*sInvocation Field Length: ", indent + 2, "");
4171 kmip_print_integer(f, value->invocation_field_length);
4172 fprintf(f, "\n");
4173
4174 fprintf(f, "%*sCounter Length: ", indent + 2, "");
4175 kmip_print_integer(f, value->counter_length);
4176 fprintf(f, "\n");
4177
4178 fprintf(f, "%*sInitial Counter Value: ", indent + 2, "");
4179 kmip_print_integer(f, value->initial_counter_value);
4180 fprintf(f, "\n");
4181
4182 fprintf(f, "%*sSalt Length: ", indent + 2, "");
4183 kmip_print_integer(f, value->salt_length);
4184 fprintf(f, "\n");
4185
4186 fprintf(f, "%*sMask Generator: ", indent + 2, "");
4187 kmip_print_mask_generator_enum(f, value->mask_generator);
4188 fprintf(f, "\n");
4189
4190 fprintf(f, "%*sMask Generator Hashing Algorithm: ", indent + 2, "");
4191 kmip_print_hashing_algorithm_enum(f, value->mask_generator_hashing_algorithm);
4192 fprintf(f, "\n");
4193
4194 kmip_print_byte_string(f, indent + 2, "P Source", value->p_source);
4195
4196 fprintf(f, "%*sTrailer Field: ", indent + 2, "");
4197 kmip_print_integer(f, value->trailer_field);
4198 fprintf(f, "\n");
4199 }
4200 }
4201
4202 void
4203 kmip_print_encryption_key_information(FILE *f, int indent, EncryptionKeyInformation *value)
4204 {
4205 fprintf(f, "%*sEncryption Key Information @ %p\n", indent, "", (void *)value);
4206
4207 if(value != NULL)
4208 {
4209 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4210
4211 kmip_print_cryptographic_parameters(f, indent + 2, value->cryptographic_parameters);
4212 }
4213 }
4214
4215 void
4216 kmip_print_mac_signature_key_information(FILE *f, int indent, MACSignatureKeyInformation *value)
4217 {
4218 fprintf(f, "%*sMAC/Signature Key Information @ %p\n", indent, "", (void *)value);
4219
4220 if(value != NULL)
4221 {
4222 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4223
4224 kmip_print_cryptographic_parameters(f, indent + 2, value->cryptographic_parameters);
4225 }
4226 }
4227
4228 void
4229 kmip_print_key_wrapping_data(FILE *f, int indent, KeyWrappingData *value)
4230 {
4231 fprintf(f, "%*sKey Wrapping Data @ %p\n", indent, "", (void *)value);
4232
4233 if(value != NULL)
4234 {
4235 fprintf(f, "%*sWrapping Method: ", indent + 2, "");
4236 kmip_print_wrapping_method_enum(f, value->wrapping_method);
4237 fprintf(f, "\n");
4238
4239 kmip_print_encryption_key_information(f, indent + 2, value->encryption_key_info);
4240
4241 kmip_print_mac_signature_key_information(f, indent + 2, value->mac_signature_key_info);
4242
4243 kmip_print_byte_string(f, indent + 2, "MAC/Signature", value->mac_signature);
4244
4245 kmip_print_byte_string(f, indent + 2, "IV/Counter/Nonce", value->iv_counter_nonce);
4246
4247 fprintf(f, "%*sEncoding Option: ", indent + 2, "");
4248 kmip_print_encoding_option_enum(f, value->encoding_option);
4249 fprintf(f, "\n");
4250 }
4251
4252 return;
4253 }
4254
4255 void
4256 kmip_print_attribute_value(FILE *f, int indent, enum attribute_type type, void *value)
4257 {
4258 fprintf(f, "%*sAttribute Value: ", indent, "");
4259
4260 switch(type)
4261 {
4262 case KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION:
4263 {
4264 fprintf(f, "\n");
4265 kmip_print_application_specific_information(f, indent + 2, value);
4266 }
4267 break;
4268
4269 case KMIP_ATTR_UNIQUE_IDENTIFIER:
4270 fprintf(f, "\n");
4271 kmip_print_text_string(f, indent + 2, "Unique Identifier", value);
4272 break;
4273
4274 case KMIP_ATTR_NAME:
4275 fprintf(f, "\n");
4276 kmip_print_name(f, indent + 2, value);
4277 break;
4278
4279 case KMIP_ATTR_OBJECT_TYPE:
4280 kmip_print_object_type_enum(f, *(enum object_type *)value);
4281 fprintf(f, "\n");
4282 break;
4283
4284 case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
4285 kmip_print_cryptographic_algorithm_enum(f, *(enum cryptographic_algorithm *)value);
4286 fprintf(f, "\n");
4287 break;
4288
4289 case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
4290 fprintf(f, "%d\n", *(int32 *)value);
4291 break;
4292
4293 case KMIP_ATTR_OPERATION_POLICY_NAME:
4294 fprintf(f, "\n");
4295 kmip_print_text_string(f, indent + 2, "Operation Policy Name", value);
4296 break;
4297
4298 case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
4299 kmip_print_cryptographic_usage_mask_enums(f, indent + 2, *(int32 *)value);
4300 break;
4301
4302 case KMIP_ATTR_STATE:
4303 kmip_print_state_enum(f, *(enum state *)value);
4304 fprintf(f, "\n");
4305 break;
4306
4307 case KMIP_ATTR_OBJECT_GROUP:
4308 {
4309 fprintf(f, "\n");
4310 kmip_print_text_string(f, indent + 2, "Object Group", value);
4311 }
4312 break;
4313
4314 case KMIP_ATTR_ACTIVATION_DATE:
4315 case KMIP_ATTR_DEACTIVATION_DATE:
4316 case KMIP_ATTR_PROCESS_START_DATE:
4317 case KMIP_ATTR_PROTECT_STOP_DATE:
4318 {
4319 fprintf(f, "\n");
4320 kmip_print_date_time(f, *(int64 *)value);
4321 } break;
4322
4323 case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
4324 {
4325 fprintf(f, "\n");
4326 kmip_print_cryptographic_parameters(f, indent + 2, value);
4327 } break;
4328
4329 default:
4330 fprintf(f, "Unknown\n");
4331 break;
4332 };
4333 }
4334
4335 void
4336 kmip_print_attribute(FILE *f, int indent, Attribute *value)
4337 {
4338 fprintf(f, "%*sAttribute @ %p\n", indent, "", (void *)value);
4339
4340 if(value != NULL)
4341 {
4342 fprintf(f, "%*sAttribute Name: ", indent + 2, "");
4343 kmip_print_attribute_type_enum(f, value->type);
4344 fprintf(f, "\n");
4345
4346 fprintf(f, "%*sAttribute Index: ", indent + 2, "");
4347 kmip_print_integer(f, value->index);
4348 fprintf(f, "\n");
4349
4350 kmip_print_attribute_value(f, indent + 2, value->type, value->value);
4351 }
4352
4353 return;
4354 }
4355
4356 void
4357 kmip_print_key_material(FILE *f, int indent, enum key_format_type format, void *value)
4358 {
4359 switch(format)
4360 {
4361 case KMIP_KEYFORMAT_RAW:
4362 case KMIP_KEYFORMAT_OPAQUE:
4363 case KMIP_KEYFORMAT_PKCS1:
4364 case KMIP_KEYFORMAT_PKCS8:
4365 case KMIP_KEYFORMAT_X509:
4366 case KMIP_KEYFORMAT_EC_PRIVATE_KEY:
4367 kmip_print_byte_string(f, indent, "Key Material", (ByteString *)value);
4368 break;
4369
4370 default:
4371 fprintf(f, "%*sUnknown Key Material @ %p\n", indent, "", value);
4372 break;
4373 };
4374 }
4375
4376 void
4377 kmip_print_key_value(FILE *f, int indent, enum type type, enum key_format_type format, void *value)
4378 {
4379 switch(type)
4380 {
4381 case KMIP_TYPE_BYTE_STRING:
4382 kmip_print_byte_string(f, indent, "Key Value", (ByteString *)value);
4383 break;
4384
4385 case KMIP_TYPE_STRUCTURE:
4386 fprintf(f, "%*sKey Value @ %p\n", indent, "", value);
4387
4388 if(value != NULL)
4389 {
4390 KeyValue key_value = *(KeyValue *)value;
4391 kmip_print_key_material(f, indent + 2, format, key_value.key_material);
4392 fprintf(f, "%*sAttributes: %zu\n", indent + 2, "", key_value.attribute_count);
4393 for(size_t i = 0; i < key_value.attribute_count; i++)
4394 {
4395 kmip_print_attribute(f, indent + 2, &key_value.attributes[i]);
4396 }
4397 }
4398 break;
4399
4400 default:
4401 fprintf(f, "%*sUnknown Key Value @ %p\n", indent, "", value);
4402 break;
4403 };
4404 }
4405
4406 void
4407 kmip_print_key_block(FILE *f, int indent, KeyBlock *value)
4408 {
4409 fprintf(f, "%*sKey Block @ %p\n", indent, "", (void *)value);
4410
4411 if(value != NULL)
4412 {
4413 fprintf(f, "%*sKey Format Type: ", indent + 2, "");
4414 kmip_print_key_format_type_enum(f, value->key_format_type);
4415 fprintf(f, "\n");
4416
4417 fprintf(f, "%*sKey Compression Type: ", indent + 2, "");
4418 kmip_print_key_compression_type_enum(f, value->key_compression_type);
4419 fprintf(f, "\n");
4420
4421 kmip_print_key_value(f, indent + 2, value->key_value_type, value->key_format_type, value->key_value);
4422
4423 fprintf(f, "%*sCryptographic Algorithm: ", indent + 2, "");
4424 kmip_print_cryptographic_algorithm_enum(f, value->cryptographic_algorithm);
4425 fprintf(f, "\n");
4426
4427 fprintf(f, "%*sCryptographic Length: %d\n", indent + 2, "", value->cryptographic_length);
4428
4429 kmip_print_key_wrapping_data(f, indent + 2, value->key_wrapping_data);
4430 }
4431
4432 return;
4433 }
4434
4435 void
4436 kmip_print_symmetric_key(FILE *f, int indent, SymmetricKey *value)
4437 {
4438 fprintf(f, "%*sSymmetric Key @ %p\n", indent, "", (void *)value);
4439
4440 if(value != NULL)
4441 {
4442 kmip_print_key_block(f, indent + 2, value->key_block);
4443 }
4444
4445 return;
4446 }
4447
4448 void
4449 kmip_print_object(FILE *f, int indent, enum object_type type, void *value)
4450 {
4451 switch(type)
4452 {
4453 case KMIP_OBJTYPE_SYMMETRIC_KEY:
4454 kmip_print_symmetric_key(f, indent, (SymmetricKey *)value);
4455 break;
4456
4457 default:
4458 fprintf(f, "%*sUnknown Object @ %p\n", indent, "", value);
4459 break;
4460 };
4461 }
4462
4463 void
4464 kmip_print_key_wrapping_specification(FILE *f, int indent, KeyWrappingSpecification *value)
4465 {
4466 fprintf(f, "%*sKey Wrapping Specification @ %p\n", indent, "", (void *)value);
4467 }
4468
4469 void
4470 kmip_print_attributes(FILE *f, int indent, Attributes *value)
4471 {
4472 fprintf(f, "%*sAttributes @ %p\n", indent, "", (void *)value);
4473
4474 if(value != NULL &&
4475 value->attribute_list != NULL)
4476 {
4477 fprintf(f, "%*sAttributes: %zu\n", indent + 2, "", value->attribute_list->size);
4478 LinkedListItem *curr = value->attribute_list->head;
4479 while(curr != NULL)
4480 {
4481 Attribute *attribute = (Attribute *)curr->data;
4482 kmip_print_attribute(f, indent + 4, attribute);
4483
4484 curr = curr->next;
4485 }
4486 }
4487 }
4488
4489 void
4490 kmip_print_template_attribute(FILE *f, int indent, TemplateAttribute *value)
4491 {
4492 fprintf(f, "%*sTemplate Attribute @ %p\n", indent, "", (void *)value);
4493
4494 if(value != NULL)
4495 {
4496 fprintf(f, "%*sNames: %zu\n", indent + 2, "", value->name_count);
4497 for(size_t i = 0; i < value->name_count; i++)
4498 {
4499 kmip_print_name(f, indent + 4, &value->names[i]);
4500 }
4501
4502 fprintf(f, "%*sAttributes: %zu\n", indent + 2, "", value->attribute_count);
4503 for(size_t i = 0; i< value->attribute_count; i++)
4504 {
4505 kmip_print_attribute(f, indent + 4, &value->attributes[i]);
4506 }
4507 }
4508 }
4509
4510 void
4511 kmip_print_create_request_payload(FILE *f, int indent, CreateRequestPayload *value)
4512 {
4513 fprintf(f, "%*sCreate Request Payload @ %p\n", indent, "", (void *)value);
4514
4515 if(value != NULL)
4516 {
4517 fprintf(f, "%*sObject Type: ", indent + 2, "");
4518 kmip_print_object_type_enum(f, value->object_type);
4519 fprintf(f, "\n");
4520
4521 kmip_print_template_attribute(f, indent + 2, value->template_attribute);
4522 kmip_print_attributes(f, indent + 2, value->attributes);
4523 kmip_print_protection_storage_masks(f, indent + 2, value->protection_storage_masks);
4524 }
4525 }
4526
4527 void
4528 kmip_print_create_response_payload(FILE *f, int indent, CreateResponsePayload *value)
4529 {
4530 fprintf(f, "%*sCreate Response Payload @ %p\n", indent, "", (void *)value);
4531
4532 if(value != NULL)
4533 {
4534 fprintf(f, "%*sObject Type: ", indent + 2, "");
4535 kmip_print_object_type_enum(f, value->object_type);
4536 fprintf(f, "\n");
4537
4538 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4539 kmip_print_template_attribute(f, indent + 2, value->template_attribute);
4540 }
4541 }
4542
4543 void
4544 kmip_print_register_request_payload(FILE *f, int indent, RegisterRequestPayload *value)
4545 {
4546 fprintf(f, "%*sCreate Request Payload @ %p\n", indent, "", (void *)value);
4547
4548 if(value != NULL)
4549 {
4550 fprintf(f, "%*sObject Type: ", indent + 2, "");
4551 kmip_print_object_type_enum(f, value->object_type);
4552 fprintf(f, "\n");
4553
4554 kmip_print_template_attribute(f, indent + 2, value->template_attribute);
4555 kmip_print_attributes(f, indent + 2, value->attributes);
4556 kmip_print_protection_storage_masks(f, indent + 2, value->protection_storage_masks);
4557
4558 kmip_print_symmetric_key(f, indent + 2, &value->object);
4559 }
4560 }
4561
4562 void
4563 kmip_print_register_response_payload(FILE *f, int indent, RegisterResponsePayload *value)
4564 {
4565 fprintf(f, "%*sCreate Response Payload @ %p\n", indent, "", (void *)value);
4566
4567 if(value != NULL)
4568 {
4569 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4570 kmip_print_template_attribute(f, indent + 2, value->template_attribute);
4571 }
4572 }
4573
4574 void
4575 kmip_print_get_request_payload(FILE *f, int indent, GetRequestPayload *value)
4576 {
4577 fprintf(f, "%*sGet Request Payload @ %p\n", indent, "", (void *)value);
4578
4579 if(value != NULL)
4580 {
4581 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4582
4583 fprintf(f, "%*sKey Format Type: ", indent + 2, "");
4584 kmip_print_key_format_type_enum(f, value->key_format_type);
4585 fprintf(f, "\n");
4586
4587 fprintf(f, "%*sKey Wrap Type: ", indent + 2, "");
4588 kmip_print_key_wrap_type_enum(f, value->key_wrap_type);
4589 fprintf(f, "\n");
4590
4591 fprintf(f, "%*sKey Compression Type: ", indent + 2, "");
4592 kmip_print_key_compression_type_enum(f, value->key_compression_type);
4593 fprintf(f, "\n");
4594
4595 kmip_print_key_wrapping_specification(f, indent + 2, value->key_wrapping_spec);
4596 }
4597 }
4598
4599 void
4600 kmip_print_get_response_payload(FILE *f, int indent, GetResponsePayload *value)
4601 {
4602 fprintf(f, "%*sGet Response Payload @ %p\n", indent, "", (void *)value);
4603
4604 if(value != NULL)
4605 {
4606 fprintf(f, "%*sObject Type: ", indent + 2, "");
4607 kmip_print_object_type_enum(f, value->object_type);
4608 fprintf(f, "\n");
4609
4610 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4611 kmip_print_object(f, indent + 2, value->object_type, value->object);
4612 }
4613
4614 return;
4615 }
4616
4617 void
4618 kmip_print_get_attribute_request_payload(FILE *f, int indent, GetAttributeRequestPayload *value)
4619 {
4620 fprintf(f, "%*sGet Attribute Request Payload @ %p\n", indent, "", (void *)value);
4621
4622 if(value != NULL)
4623 {
4624 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4625 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->attribute_name);
4626 }
4627 }
4628
4629 void
4630 kmip_print_get_attribute_response_payload(FILE *f, int indent, GetAttributeResponsePayload *value)
4631 {
4632 fprintf(f, "%*sGet Response Payload @ %p\n", indent, "", (void *)value);
4633
4634 if(value != NULL)
4635 {
4636 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4637 kmip_print_attribute(f, indent + 2, value->attribute);
4638 }
4639
4640 return;
4641 }
4642
4643 void
4644 kmip_print_destroy_request_payload(FILE *f, int indent, DestroyRequestPayload *value)
4645 {
4646 fprintf(f, "%*sDestroy Request Payload @ %p\n", indent, "", (void *)value);
4647
4648 if(value != NULL)
4649 {
4650 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4651 }
4652 }
4653
4654 void
4655 kmip_print_destroy_response_payload(FILE *f, int indent, DestroyResponsePayload *value)
4656 {
4657 fprintf(f, "%*sDestroy Response Payload @ %p\n", indent, "", (void *)value);
4658
4659 if(value != NULL)
4660 {
4661 kmip_print_text_string(f, indent + 2, "Unique Identifier", value->unique_identifier);
4662 }
4663 }
4664
4665 void
4666 kmip_print_request_payload(FILE *f, int indent, enum operation type, void *value)
4667 {
4668 switch(type)
4669 {
4670 case KMIP_OP_CREATE:
4671 kmip_print_create_request_payload(f, indent, value);
4672 break;
4673
4674 case KMIP_OP_REGISTER:
4675 kmip_print_register_request_payload(f, indent, value);
4676 break;
4677
4678 case KMIP_OP_GET:
4679 kmip_print_get_request_payload(f, indent, (GetRequestPayload *)value);
4680 break;
4681
4682 case KMIP_OP_GET_ATTRIBUTES:
4683 kmip_print_get_attribute_request_payload(f, indent, (GetAttributeRequestPayload *)value);
4684 break;
4685
4686 case KMIP_OP_DESTROY:
4687 kmip_print_destroy_request_payload(f, indent, value);
4688 break;
4689
4690 case KMIP_OP_QUERY:
4691 kmip_print_query_request_payload(f, indent, value);
4692 break;
4693
4694 case KMIP_OP_LOCATE:
4695 kmip_print_locate_request_payload(f, indent, value);
4696 break;
4697
4698 default:
4699 fprintf(f, "%*sUnknown Payload @ %p\n", indent, "", value);
4700 break;
4701 };
4702 }
4703
4704 void
4705 kmip_print_response_payload(FILE *f, int indent, enum operation type, void *value)
4706 {
4707 switch(type)
4708 {
4709 case KMIP_OP_CREATE:
4710 kmip_print_create_response_payload(f, indent, value);
4711 break;
4712
4713 case KMIP_OP_REGISTER:
4714 kmip_print_register_response_payload(f, indent, value);
4715 break;
4716
4717 case KMIP_OP_GET:
4718 kmip_print_get_response_payload(f, indent, (GetResponsePayload *)value);
4719 break;
4720
4721 case KMIP_OP_GET_ATTRIBUTES:
4722 kmip_print_get_attribute_response_payload(f, indent, (GetAttributeResponsePayload *)value);
4723 break;
4724
4725 case KMIP_OP_DESTROY:
4726 kmip_print_destroy_response_payload(f, indent, value);
4727 break;
4728
4729 case KMIP_OP_QUERY:
4730 kmip_print_query_response_payload(f, indent, value);
4731 break;
4732
4733 case KMIP_OP_LOCATE:
4734 kmip_print_locate_response_payload(f, indent, value);
4735 break;
4736
4737 default:
4738 fprintf(f, "%*sUnknown Payload @ %p\n", indent, "", value);
4739 break;
4740 };
4741 }
4742
4743 void
4744 kmip_print_username_password_credential(FILE *f, int indent, UsernamePasswordCredential *value)
4745 {
4746 fprintf(f, "%*sUsername/Password Credential @ %p\n", indent, "", (void *)value);
4747
4748 if(value != NULL)
4749 {
4750 kmip_print_text_string(f, indent + 2, "Username", value->username);
4751 kmip_print_text_string(f, indent + 2, "Password", value->password);
4752 }
4753 }
4754
4755 void
4756 kmip_print_device_credential(FILE *f, int indent, DeviceCredential *value)
4757 {
4758 fprintf(f, "%*sDevice Credential @ %p\n", indent, "", (void *)value);
4759
4760 if(value != NULL)
4761 {
4762 kmip_print_text_string(f, indent + 2, "Device Serial Number", value->device_serial_number);
4763 kmip_print_text_string(f, indent + 2, "Password", value->password);
4764 kmip_print_text_string(f, indent + 2, "Device Identifier", value->device_identifier);
4765 kmip_print_text_string(f, indent + 2, "Network Identifier", value->network_identifier);
4766 kmip_print_text_string(f, indent + 2, "Machine Identifier", value->machine_identifier);
4767 kmip_print_text_string(f, indent + 2, "Media Identifier", value->media_identifier);
4768 }
4769 }
4770
4771 void
4772 kmip_print_attestation_credential(FILE *f, int indent, AttestationCredential *value)
4773 {
4774 fprintf(f, "%*sAttestation Credential @ %p\n", indent, "", (void *)value);
4775
4776 if(value != NULL)
4777 {
4778 kmip_print_nonce(f, indent + 2, value->nonce);
4779 fprintf(f, "%*sAttestation Type: ", indent + 2, "");
4780 kmip_print_attestation_type_enum(f, value->attestation_type);
4781 fprintf(f, "\n");
4782 kmip_print_byte_string(f, indent + 2, "Attestation Measurement", value->attestation_measurement);
4783 kmip_print_byte_string(f, indent + 2, "Attestation Assertion", value->attestation_assertion);
4784 }
4785 }
4786
4787 void
4788 kmip_print_credential_value(FILE *f, int indent, enum credential_type type, void *value)
4789 {
4790 fprintf(f, "%*sCredential Value @ %p\n", indent, "", value);
4791
4792 if(value != NULL)
4793 {
4794 switch(type)
4795 {
4796 case KMIP_CRED_USERNAME_AND_PASSWORD:
4797 kmip_print_username_password_credential(f, indent + 2, value);
4798 break;
4799
4800 case KMIP_CRED_DEVICE:
4801 kmip_print_device_credential(f, indent + 2, value);
4802 break;
4803
4804 case KMIP_CRED_ATTESTATION:
4805 kmip_print_attestation_credential(f, indent + 2, value);
4806 break;
4807
4808 default:
4809 fprintf(f, "%*sUnknown Credential @ %p\n", indent + 2, "", value);
4810 break;
4811 };
4812 }
4813 }
4814
4815 void
4816 kmip_print_credential(FILE *f, int indent, Credential *value)
4817 {
4818 fprintf(f, "%*sCredential @ %p\n", indent, "", (void *)value);
4819
4820 if(value != NULL)
4821 {
4822 fprintf(f, "%*sCredential Type: ", indent + 2, "");
4823 kmip_print_credential_type_enum(f, value->credential_type);
4824 fprintf(f, "\n");
4825
4826 kmip_print_credential_value(f, indent + 2, value->credential_type, value->credential_value);
4827 }
4828 }
4829
4830 void
4831 kmip_print_authentication(FILE *f, int indent, Authentication *value)
4832 {
4833 fprintf(f, "%*sAuthentication @ %p\n", indent, "", (void *)value);
4834
4835 if(value != NULL)
4836 {
4837 kmip_print_credential(f, indent + 2, value->credential);
4838 }
4839 }
4840
4841 void
4842 kmip_print_request_batch_item(FILE *f, int indent, RequestBatchItem *value)
4843 {
4844 fprintf(f, "%*sRequest Batch Item @ %p\n", indent, "", (void *)value);
4845
4846 if(value != NULL)
4847 {
4848 fprintf(f, "%*sOperation: ", indent + 2, "");
4849 kmip_print_operation_enum(f, value->operation);
4850 fprintf(f, "\n");
4851
4852 fprintf(f, "%*sEphemeral: ", indent + 2, "");
4853 kmip_print_bool(f, value->ephemeral);
4854 fprintf(f, "\n");
4855
4856 kmip_print_byte_string(f, indent + 2, "Unique Batch Item ID", value->unique_batch_item_id);
4857 kmip_print_request_payload(f, indent + 2, value->operation, value->request_payload);
4858 }
4859 }
4860
4861 void
4862 kmip_print_response_batch_item(FILE *f, int indent, ResponseBatchItem *value)
4863 {
4864 fprintf(f, "%*sResponse Batch Item @ %p\n", indent, "", (void *)value);
4865
4866 if(value != NULL)
4867 {
4868 fprintf(f, "%*sOperation: ", indent + 2, "");
4869 kmip_print_operation_enum(f, value->operation);
4870 fprintf(f, "\n");
4871
4872 kmip_print_byte_string(f, indent + 2, "Unique Batch Item ID", value->unique_batch_item_id);
4873
4874 fprintf(f, "%*sResult Status: ", indent + 2, "");
4875 kmip_print_result_status_enum(f, value->result_status);
4876 fprintf(f, "\n");
4877
4878 fprintf(f, "%*sResult Reason: ", indent + 2, "");
4879 kmip_print_result_reason_enum(f, value->result_reason);
4880 fprintf(f, "\n");
4881
4882 kmip_print_text_string(f, indent + 2, "Result Message", value->result_message);
4883 kmip_print_byte_string(f, indent + 2, "Asynchronous Correlation Value", value->asynchronous_correlation_value);
4884
4885 kmip_print_response_payload(f, indent + 2, value->operation, value->response_payload);
4886 }
4887
4888 return;
4889 }
4890
4891 void
4892 kmip_print_request_header(FILE *f, int indent, RequestHeader *value)
4893 {
4894 fprintf(f, "%*sRequest Header @ %p\n", indent, "", (void *)value);
4895
4896 if(value != NULL)
4897 {
4898 kmip_print_protocol_version(f, indent + 2, value->protocol_version);
4899
4900 fprintf(f, "%*sMaximum Response Size: ", indent + 2, "");
4901 kmip_print_integer(f, value->maximum_response_size);
4902 fprintf(f, "\n");
4903
4904 kmip_print_text_string(f, indent + 2, "Client Correlation Value", value->client_correlation_value);
4905 kmip_print_text_string(f, indent + 2, "Server Correlation Value", value->server_correlation_value);
4906 fprintf(f, "%*sAsynchronous Indicator: ", indent + 2, "");
4907 kmip_print_bool(f, value->asynchronous_indicator);
4908 fprintf(f, "\n");
4909 fprintf(f, "%*sAttestation Capable Indicator: ", indent + 2, "");
4910 kmip_print_bool(f, value->attestation_capable_indicator);
4911 fprintf(f, "\n");
4912 fprintf(f, "%*sAttestation Types: %zu\n", indent + 2, "", value->attestation_type_count);
4913 for(size_t i = 0; i < value->attestation_type_count; i++)
4914 {
4915 /* TODO (ph) Add enum value -> string functionality. */
4916 fprintf(f, "%*sAttestation Type: %s\n", indent + 4, "", "???");
4917 }
4918 kmip_print_authentication(f, indent + 2, value->authentication);
4919 fprintf(f, "%*sBatch Error Continuation Option: ", indent + 2, "");
4920 kmip_print_batch_error_continuation_option(f, value->batch_error_continuation_option);
4921 fprintf(f, "\n");
4922 fprintf(f, "%*sBatch Order Option: ", indent + 2, "");
4923 kmip_print_bool(f, value->batch_order_option);
4924 fprintf(f, "\n");
4925 fprintf(f, "%*sTime Stamp: ", indent + 2, "");
4926 kmip_print_date_time(f, value->time_stamp);
4927 fprintf(f, "\n");
4928 fprintf(f, "%*sBatch Count: %d\n", indent + 2, "", value->batch_count);
4929 }
4930 }
4931
4932 void
4933 kmip_print_response_header(FILE *f, int indent, ResponseHeader *value)
4934 {
4935 fprintf(f, "%*sResponse Header @ %p\n", indent, "", (void *)value);
4936
4937 if(value != NULL)
4938 {
4939 kmip_print_protocol_version(f, indent + 2, value->protocol_version);
4940 fprintf(f, "%*sTime Stamp: ", indent + 2, "");
4941 kmip_print_date_time(f, value->time_stamp);
4942 fprintf(f, "\n");
4943 kmip_print_nonce(f, indent + 2, value->nonce);
4944
4945 kmip_print_byte_string(f, indent + 2, "Server Hashed Password", value->server_hashed_password);
4946
4947 fprintf(f, "%*sAttestation Types: %zu\n", indent + 2, "", value->attestation_type_count);
4948 for(size_t i = 0; i < value->attestation_type_count; i++)
4949 {
4950 /* TODO (ph) Add enum value -> string functionality. */
4951 fprintf(f, "%*sAttestation Type: %s\n", indent + 4, "", "???");
4952 }
4953 kmip_print_text_string(f, indent + 2, "Client Correlation Value", value->client_correlation_value);
4954 kmip_print_text_string(f, indent + 2, "Server Correlation Value", value->server_correlation_value);
4955 fprintf(f, "%*sBatch Count: %d\n", indent + 2, "", value->batch_count);
4956 }
4957 }
4958
4959 void
4960 kmip_print_request_message(FILE *f, RequestMessage *value)
4961 {
4962 fprintf(f, "Request Message @ %p\n", (void *)value);
4963
4964 if(value != NULL)
4965 {
4966 kmip_print_request_header(f, 2, value->request_header);
4967 fprintf(f, "%*sBatch Items: %zu\n", 2, "", value->batch_count);
4968
4969 for(size_t i = 0; i < value->batch_count; i++)
4970 {
4971 kmip_print_request_batch_item(f, 4, &value->batch_items[i]);
4972 }
4973 }
4974
4975 return;
4976 }
4977
4978 void
4979 kmip_print_response_message(FILE *f, ResponseMessage *value)
4980 {
4981 fprintf(f, "Response Message @ %p\n", (void *)value);
4982
4983 if(value != NULL)
4984 {
4985 kmip_print_response_header(f, 2, value->response_header);
4986 fprintf(f, " Batch Items: %zu\n", value->batch_count);
4987
4988 for(size_t i = 0; i < value->batch_count; i++)
4989 {
4990 kmip_print_response_batch_item(f, 4, &value->batch_items[i]);
4991 }
4992 }
4993
4994 return;
4995 }
4996
4997 void
4998 kmip_print_query_function_enum(FILE* f, int indent, enum query_function value)
4999 {
5000 if(value == 0)
5001 {
5002 fprintf(f, "%*s-", indent, "");
5003 return;
5004 }
5005
5006 switch(value)
5007 {
5008 /* KMIP 1.0 */
5009 case KMIP_QUERY_OPERATIONS:
5010 fprintf(f, "%*sOperations", indent, "");
5011 break;
5012 case KMIP_QUERY_OBJECTS:
5013 fprintf(f, "%*sObjects", indent, "");
5014 break;
5015 case KMIP_QUERY_SERVER_INFORMATION:
5016 fprintf(f, "%*sServer Information", indent, "");
5017 break;
5018 case KMIP_QUERY_APPLICATION_NAMESPACES:
5019 fprintf(f, "%*sApplication namespaces", indent, "");
5020 break;
5021 /* KMIP 1.1 */
5022 case KMIP_QUERY_EXTENSION_LIST:
5023 fprintf(f, "%*sExtension list", indent, "");
5024 break;
5025 case KMIP_QUERY_EXTENSION_MAP:
5026 fprintf(f, "%*sExtension Map", indent, "");
5027 break;
5028 /* KMIP 1.2 */
5029 case KMIP_QUERY_ATTESTATION_TYPES:
5030 fprintf(f, "%*sAttestation Types", indent, "");
5031 break;
5032 /* KMIP 1.3 */
5033 case KMIP_QUERY_RNGS:
5034 fprintf(f, "%*sRNGS", indent, "");
5035 break;
5036 case KMIP_QUERY_VALIDATIONS:
5037 fprintf(f, "%*sValidations", indent, "");
5038 break;
5039 case KMIP_QUERY_PROFILES:
5040 fprintf(f, "%*sProfiles", indent, "");
5041 break;
5042 case KMIP_QUERY_CAPABILITIES:
5043 fprintf(f, "%*sCapabilities", indent, "");
5044 break;
5045 case KMIP_QUERY_CLIENT_REGISTRATION_METHODS:
5046 fprintf(f, "%*sRegistration Methods", indent, "");
5047 break;
5048 /* KMIP 2.0 */
5049 case KMIP_QUERY_DEFAULTS_INFORMATION:
5050 fprintf(f, "%*sDefaults Information", indent, "");
5051 break;
5052 case KMIP_QUERY_STORAGE_PROTECTION_MASKS:
5053 fprintf(f, "%*sStorage Protection Masks", indent, "");
5054 break;
5055
5056 default:
5057 fprintf(f, "%*sUnknown", indent, "");
5058 break;
5059 };
5060 }
5061
5062 void
5063 kmip_print_query_functions(FILE* f, int indent, Functions* value)
5064 {
5065 fprintf(f, "%*sQuery Functions @ %p\n", indent, "", (void *)value);
5066
5067 if(value != NULL &&
5068 value->function_list != NULL)
5069 {
5070 fprintf(f, "%*sFunctions: %zu\n", indent + 2, "", value->function_list->size);
5071 LinkedListItem *curr = value->function_list->head;
5072 size_t count = 1;
5073 while(curr != NULL)
5074 {
5075 fprintf(f, "%*sFunction: %zu: ", indent + 4, "", count);
5076 int32 func = *(int32 *)curr->data;
5077 kmip_print_query_function_enum(f, indent + 6, func);
5078 fprintf(f, "\n");
5079
5080 curr = curr->next;
5081 count++;
5082 }
5083 }
5084 }
5085
5086
5087 void
5088 kmip_print_operations(FILE* f, int indent, Operations *value)
5089 {
5090 fprintf(f, "%*sOperations @ %p\n", indent, "", (void *)value);
5091
5092 if(value != NULL &&
5093 value->operation_list != NULL)
5094 {
5095 fprintf(f, "%*sOperations: %zu\n", indent + 2, "", value->operation_list->size);
5096 LinkedListItem *curr = value->operation_list->head;
5097 size_t count = 1;
5098 while(curr != NULL)
5099 {
5100 fprintf(f, "%*sOperation: %zu: ", indent + 4, "", count);
5101 int32 oper = *(int32 *)curr->data;
5102 kmip_print_operation_enum(f, oper);
5103 fprintf(f, "\n");
5104
5105 curr = curr->next;
5106 count++;
5107 }
5108 }
5109 }
5110
5111 void
5112 kmip_print_object_types(FILE* f, int indent, ObjectTypes* value)
5113 {
5114 fprintf(f, "%*sObjects @ %p\n", indent, "", (void *)value);
5115
5116 if(value != NULL &&
5117 value->object_list != NULL )
5118 {
5119 fprintf(f, "%*sObjects: %zu\n", indent + 2, "", value->object_list->size);
5120 LinkedListItem *curr = value->object_list->head;
5121 size_t count = 1;
5122 while(curr != NULL)
5123 {
5124 fprintf(f, "%*sObject: %zu: ", indent + 4, "", count);
5125 int32 obj = *(int32 *)curr->data;
5126 kmip_print_object_type_enum(f, obj);
5127 fprintf(f, "\n");
5128
5129 curr = curr->next;
5130 count++;
5131 }
5132 }
5133 }
5134
5135 void
5136 kmip_print_alternative_endpoints(FILE* f, int indent, AltEndpoints* value)
5137 {
5138 fprintf(f, "%*sAlt Endpointss @ %p\n", indent, "", (void *)value);
5139
5140 if(value != NULL &&
5141 value->endpoint_list != NULL )
5142 {
5143 fprintf(f, "%*sAlt Endpoints: %zu\n", indent + 2, "", value->endpoint_list->size);
5144 LinkedListItem *curr = value->endpoint_list->head;
5145 size_t count = 1;
5146 while(curr != NULL)
5147 {
5148 fprintf(f, "%*sEndpoint: %zu: ", indent + 4, "", count);
5149 TextString* endpoint = (TextString*)curr->data;
5150 kmip_print_text_string(f, indent + 2, "Endpoint", endpoint);
5151 fprintf(f, "\n");
5152
5153 curr = curr->next;
5154 count++;
5155 }
5156 }
5157 }
5158
5159 void
5160 kmip_print_server_information(FILE* f, int indent, ServerInformation* value)
5161 {
5162 fprintf(f,"%*sServer Information @ %p\n", indent, "", (void *)value);
5163
5164 if(value != NULL)
5165 {
5166 kmip_print_text_string(f,indent + 2, "Server Name", value->server_name);
5167 kmip_print_text_string(f,indent + 2, "Server Serial Number", value->server_serial_number);
5168 kmip_print_text_string(f,indent + 2, "Server Version", value->server_version);
5169 kmip_print_text_string(f,indent + 2, "Server Load", value->server_load);
5170 kmip_print_text_string(f,indent + 2, "Product Name", value->product_name);
5171 kmip_print_text_string(f,indent + 2, "Build Level", value->build_level);
5172 kmip_print_text_string(f,indent + 2, "Build Date", value->build_date);
5173 kmip_print_text_string(f,indent + 2, "Cluster info", value->cluster_info);
5174
5175 kmip_print_alternative_endpoints(f,indent+2, value->alternative_failover_endpoints);
5176 }
5177 }
5178
5179
5180 void
5181 kmip_print_query_response_payload(FILE* f, int indent, QueryResponsePayload *value)
5182 {
5183 fprintf(f,"%*sQuery response @ %p\n", indent, "", (void *)value);
5184
5185 if(value != NULL)
5186 {
5187 kmip_print_operations(f,indent, value->operations);
5188 kmip_print_object_types(f,indent, value->objects);
5189 kmip_print_text_string(f,indent, "Vendor ID", value->vendor_identification);
5190 kmip_print_server_information(f,indent, value->server_information);
5191 }
5192 }
5193
5194 void
5195 kmip_print_query_request_payload(FILE* f, int indent, QueryRequestPayload *value)
5196 {
5197 fprintf(f,"%*sQuery request @ %p\n", indent, "", (void *)value);
5198
5199 if(value != NULL)
5200 kmip_print_query_functions(f, indent, value->functions);
5201 }
5202
5203
5204 /*
5205 Freeing Functions
5206 */
5207
5208 void
5209 kmip_free_buffer(KMIP *ctx, void *buffer, size_t size)
5210 {
5211 if(ctx == NULL)
5212 {
5213 return;
5214 }
5215
5216 ctx->memset_func(buffer, 0, size);
5217 ctx->free_func(ctx->state, buffer);
5218 }
5219
5220 void
5221 kmip_free_text_string(KMIP *ctx, TextString *value)
5222 {
5223 if(ctx == NULL)
5224 {
5225 return;
5226 }
5227
5228 if(value != NULL)
5229 {
5230 if(value->value != NULL)
5231 {
5232 ctx->memset_func(value->value, 0, value->size);
5233 ctx->free_func(ctx->state, value->value);
5234
5235 value->value = NULL;
5236 }
5237
5238 value->size = 0;
5239 }
5240
5241 return;
5242 }
5243
5244 void
5245 kmip_free_byte_string(KMIP *ctx, ByteString *value)
5246 {
5247 if(value != NULL)
5248 {
5249 if(value->value != NULL)
5250 {
5251 ctx->memset_func(value->value, 0, value->size);
5252 ctx->free_func(ctx->state, value->value);
5253
5254 value->value = NULL;
5255 }
5256
5257 value->size = 0;
5258 }
5259
5260 return;
5261 }
5262
5263 void
5264 kmip_free_name(KMIP *ctx, Name *value)
5265 {
5266 if(value != NULL)
5267 {
5268 if(value->value != NULL)
5269 {
5270 kmip_free_text_string(ctx, value->value);
5271 ctx->free_func(ctx->state, value->value);
5272
5273 value->value = NULL;
5274 }
5275
5276 value->type = 0;
5277 }
5278
5279 return;
5280 }
5281
5282 void
5283 kmip_free_protection_storage_masks(KMIP *ctx, ProtectionStorageMasks *value)
5284 {
5285 if(value != NULL)
5286 {
5287 if(value->masks != NULL)
5288 {
5289 LinkedListItem *curr = kmip_linked_list_pop(value->masks);
5290 while(curr != NULL)
5291 {
5292 ctx->free_func(ctx->state, curr->data);
5293 curr->data = NULL;
5294 ctx->free_func(ctx->state, curr);
5295 curr = kmip_linked_list_pop(value->masks);
5296 }
5297 ctx->free_func(ctx->state, value->masks);
5298 value->masks = NULL;
5299 }
5300 }
5301
5302 return;
5303 }
5304
5305 void
5306 kmip_free_attribute(KMIP *ctx, Attribute *value)
5307 {
5308 if(value != NULL)
5309 {
5310 if(value->value != NULL)
5311 {
5312 switch(value->type)
5313 {
5314 case KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION:
5315 {
5316 kmip_free_application_specific_information(ctx, value->value);
5317 }
5318 break;
5319
5320 case KMIP_ATTR_UNIQUE_IDENTIFIER:
5321 kmip_free_text_string(ctx, value->value);
5322 break;
5323
5324 case KMIP_ATTR_NAME:
5325 kmip_free_name(ctx, value->value);
5326 break;
5327
5328 case KMIP_ATTR_OBJECT_TYPE:
5329 *(int32*)value->value = 0;
5330 break;
5331
5332 case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
5333 *(int32*)value->value = 0;
5334 break;
5335
5336 case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
5337 *(int32*)value->value = KMIP_UNSET;
5338 break;
5339
5340 case KMIP_ATTR_OPERATION_POLICY_NAME:
5341 kmip_free_text_string(ctx, value->value);
5342 break;
5343
5344 case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
5345 *(int32*)value->value = KMIP_UNSET;
5346 break;
5347
5348 case KMIP_ATTR_STATE:
5349 *(int32*)value->value = 0;
5350 break;
5351
5352 case KMIP_ATTR_OBJECT_GROUP:
5353 {
5354 kmip_free_text_string(ctx, value->value);
5355 }
5356 break;
5357
5358 case KMIP_ATTR_ACTIVATION_DATE:
5359 case KMIP_ATTR_DEACTIVATION_DATE:
5360 case KMIP_ATTR_PROCESS_START_DATE:
5361 case KMIP_ATTR_PROTECT_STOP_DATE:
5362 {
5363 *(int64*)value->value = KMIP_UNSET;
5364 } break;
5365
5366 case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
5367 {
5368 kmip_free_cryptographic_parameters(ctx, value->value);
5369 } break;
5370
5371 default:
5372 /* NOTE (ph) Hitting this case means that we don't know what the */
5373 /* actual type, size, or value of value->value is. We can */
5374 /* still free it but we cannot securely zero the memory. We */
5375 /* also do not know how to free any possible substructures */
5376 /* pointed to within value->value. */
5377 /* */
5378 /* Avoid hitting this case at all costs. */
5379 break;
5380 };
5381
5382 ctx->free_func(ctx->state, value->value);
5383 value->value = NULL;
5384 }
5385
5386 value->type = 0;
5387 value->index = KMIP_UNSET;
5388 }
5389
5390 return;
5391 }
5392
5393 void
5394 kmip_free_attributes(KMIP *ctx, Attributes *value)
5395 {
5396 if(value != NULL)
5397 {
5398 if(value->attribute_list != NULL)
5399 {
5400 LinkedListItem *curr = kmip_linked_list_pop(value->attribute_list);
5401 while(curr != NULL)
5402 {
5403 Attribute *attribute = (Attribute *)curr->data;
5404 kmip_free_attribute(ctx, attribute);
5405 ctx->free_func(ctx->state, attribute);
5406 ctx->free_func(ctx->state, curr);
5407 curr = kmip_linked_list_pop(value->attribute_list);
5408 }
5409 ctx->free_func(ctx->state, value->attribute_list);
5410
5411 value->attribute_list = NULL;
5412 }
5413 }
5414
5415 return;
5416 }
5417
5418 void
5419 kmip_free_template_attribute(KMIP *ctx, TemplateAttribute *value)
5420 {
5421 if(value != NULL)
5422 {
5423 if(value->names != NULL)
5424 {
5425 for(size_t i = 0; i < value->name_count; i++)
5426 {
5427 kmip_free_name(ctx, &value->names[i]);
5428 }
5429 ctx->free_func(ctx->state, value->names);
5430
5431 value->names = NULL;
5432 }
5433
5434 value->name_count = 0;
5435
5436 if(value->attributes != NULL)
5437 {
5438 for(size_t i = 0; i < value->attribute_count; i++)
5439 {
5440 kmip_free_attribute(ctx, &value->attributes[i]);
5441 }
5442 ctx->free_func(ctx->state, value->attributes);
5443
5444 value->attributes = NULL;
5445 }
5446
5447 value->attribute_count = 0;
5448 }
5449
5450 return;
5451 }
5452
5453 void
5454 kmip_free_transparent_symmetric_key(KMIP *ctx, TransparentSymmetricKey *value)
5455 {
5456 if(value != NULL)
5457 {
5458 if(value->key != NULL)
5459 {
5460 kmip_free_byte_string(ctx, value->key);
5461
5462 ctx->free_func(ctx->state, value->key);
5463 value->key = NULL;
5464 }
5465 }
5466
5467 return;
5468 }
5469
5470 void
5471 kmip_free_key_material(KMIP *ctx, enum key_format_type format, void **value)
5472 {
5473 if(value != NULL)
5474 {
5475 if(*value != NULL)
5476 {
5477 switch(format)
5478 {
5479 case KMIP_KEYFORMAT_RAW:
5480 case KMIP_KEYFORMAT_OPAQUE:
5481 case KMIP_KEYFORMAT_PKCS1:
5482 case KMIP_KEYFORMAT_PKCS8:
5483 case KMIP_KEYFORMAT_X509:
5484 case KMIP_KEYFORMAT_EC_PRIVATE_KEY:
5485 kmip_free_byte_string(ctx, *value);
5486 break;
5487
5488 case KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY:
5489 kmip_free_transparent_symmetric_key(ctx, *value);
5490 break;
5491
5492 default:
5493 /* NOTE (ph) Hitting this case means that we don't know */
5494 /* what the actual type, size, or value of value is. */
5495 /* We can still free it but we cannot securely zero */
5496 /* the memory. We also do not know how to free any */
5497 /* possible substructures pointed to within value. */
5498 /* */
5499 /* Avoid hitting this case at all costs. */
5500 break;
5501 };
5502
5503 ctx->free_func(ctx->state, *value);
5504 *value = NULL;
5505 }
5506 }
5507
5508 return;
5509 }
5510
5511 void
5512 kmip_free_key_value(KMIP *ctx, enum key_format_type format, KeyValue *value)
5513 {
5514 if(value != NULL)
5515 {
5516 if(value->key_material != NULL)
5517 {
5518 kmip_free_key_material(ctx, format, &value->key_material);
5519 value->key_material = NULL;
5520 }
5521
5522 if(value->attributes != NULL)
5523 {
5524 for(size_t i = 0; i < value->attribute_count; i++)
5525 {
5526 kmip_free_attribute(ctx, &value->attributes[i]);
5527 }
5528 ctx->free_func(ctx->state, value->attributes);
5529
5530 value->attributes = NULL;
5531 }
5532
5533 value->attribute_count = 0;
5534 }
5535
5536 return;
5537 }
5538
5539 void
5540 kmip_free_application_specific_information(KMIP *ctx, ApplicationSpecificInformation *value)
5541 {
5542 if(value != NULL)
5543 {
5544 if(value->application_namespace != NULL)
5545 {
5546 kmip_free_text_string(ctx, value->application_namespace);
5547
5548 ctx->free_func(ctx->state, value->application_namespace);
5549 value->application_namespace = NULL;
5550 }
5551
5552 if(value->application_data != NULL)
5553 {
5554 kmip_free_text_string(ctx, value->application_data);
5555
5556 ctx->free_func(ctx->state, value->application_data);
5557 value->application_data = NULL;
5558 }
5559 }
5560
5561 return;
5562 }
5563
5564 void
5565 kmip_free_cryptographic_parameters(KMIP *ctx, CryptographicParameters *value)
5566 {
5567 if(value != NULL)
5568 {
5569 if(value->p_source != NULL)
5570 {
5571 kmip_free_byte_string(ctx, value->p_source);
5572
5573 ctx->free_func(ctx->state, value->p_source);
5574 value->p_source = NULL;
5575 }
5576
5577 kmip_init_cryptographic_parameters(value);
5578 }
5579
5580 return;
5581 }
5582
5583 void
5584 kmip_free_encryption_key_information(KMIP *ctx, EncryptionKeyInformation *value)
5585 {
5586 if(value != NULL)
5587 {
5588 if(value->unique_identifier != NULL)
5589 {
5590 kmip_free_text_string(ctx, value->unique_identifier);
5591
5592 ctx->free_func(ctx->state, value->unique_identifier);
5593 value->unique_identifier = NULL;
5594 }
5595
5596 if(value->cryptographic_parameters != NULL)
5597 {
5598 kmip_free_cryptographic_parameters(ctx, value->cryptographic_parameters);
5599
5600 ctx->free_func(ctx->state, value->cryptographic_parameters);
5601 value->cryptographic_parameters = NULL;
5602 }
5603 }
5604
5605 return;
5606 }
5607
5608 void
5609 kmip_free_mac_signature_key_information(KMIP *ctx, MACSignatureKeyInformation *value)
5610 {
5611 if(value != NULL)
5612 {
5613 if(value->unique_identifier != NULL)
5614 {
5615 kmip_free_text_string(ctx, value->unique_identifier);
5616
5617 ctx->free_func(ctx->state, value->unique_identifier);
5618 value->unique_identifier = NULL;
5619 }
5620
5621 if(value->cryptographic_parameters != NULL)
5622 {
5623 kmip_free_cryptographic_parameters(ctx, value->cryptographic_parameters);
5624
5625 ctx->free_func(ctx->state, value->cryptographic_parameters);
5626 value->cryptographic_parameters = NULL;
5627 }
5628 }
5629
5630 return;
5631 }
5632
5633 void
5634 kmip_free_key_wrapping_data(KMIP *ctx, KeyWrappingData *value)
5635 {
5636 if(value != NULL)
5637 {
5638 if(value->encryption_key_info != NULL)
5639 {
5640 kmip_free_encryption_key_information(ctx, value->encryption_key_info);
5641
5642 ctx->free_func(ctx->state, value->encryption_key_info);
5643 value->encryption_key_info = NULL;
5644 }
5645
5646 if(value->mac_signature_key_info != NULL)
5647 {
5648 kmip_free_mac_signature_key_information(ctx, value->mac_signature_key_info);
5649
5650 ctx->free_func(ctx->state, value->mac_signature_key_info);
5651 value->mac_signature_key_info = NULL;
5652 }
5653
5654 if(value->mac_signature != NULL)
5655 {
5656 kmip_free_byte_string(ctx, value->mac_signature);
5657
5658 ctx->free_func(ctx->state, value->mac_signature);
5659 value->mac_signature = NULL;
5660 }
5661
5662 if(value->iv_counter_nonce != NULL)
5663 {
5664 kmip_free_byte_string(ctx, value->iv_counter_nonce);
5665
5666 ctx->free_func(ctx->state, value->iv_counter_nonce);
5667 value->iv_counter_nonce = NULL;
5668 }
5669
5670 value->wrapping_method = 0;
5671 value->encoding_option = 0;
5672 }
5673
5674 return;
5675 }
5676
5677 void
5678 kmip_free_key_block(KMIP *ctx, KeyBlock *value)
5679 {
5680 if(value != NULL)
5681 {
5682 if(value->key_value != NULL)
5683 {
5684 if(value->key_value_type == KMIP_TYPE_BYTE_STRING)
5685 {
5686 kmip_free_byte_string(ctx, value->key_value);
5687 ctx->free_func(ctx->state, value->key_value);
5688 }
5689 else
5690 {
5691 kmip_free_key_value(ctx, value->key_format_type, value->key_value);
5692 ctx->free_func(ctx->state, value->key_value);
5693 }
5694 value->key_value = NULL;
5695 }
5696
5697 if(value->key_wrapping_data != NULL)
5698 {
5699 kmip_free_key_wrapping_data(ctx, value->key_wrapping_data);
5700 ctx->free_func(ctx->state, value->key_wrapping_data);
5701 value->key_wrapping_data = NULL;
5702 }
5703
5704 kmip_init_key_block(value);
5705 }
5706
5707 return;
5708 }
5709
5710 void
5711 kmip_free_symmetric_key(KMIP *ctx, SymmetricKey *value)
5712 {
5713 if(value != NULL)
5714 {
5715 if(value->key_block != NULL)
5716 {
5717 kmip_free_key_block(ctx, value->key_block);
5718 ctx->free_func(ctx->state, value->key_block);
5719 value->key_block = NULL;
5720 }
5721 }
5722
5723 return;
5724 }
5725
5726 void
5727 kmip_free_public_key(KMIP *ctx, PublicKey *value)
5728 {
5729 if(value != NULL)
5730 {
5731 if(value->key_block != NULL)
5732 {
5733 kmip_free_key_block(ctx, value->key_block);
5734 ctx->free_func(ctx->state, value->key_block);
5735 value->key_block = NULL;
5736 }
5737 }
5738
5739 return;
5740 }
5741
5742 void
5743 kmip_free_private_key(KMIP *ctx, PrivateKey *value)
5744 {
5745 if(value != NULL)
5746 {
5747 if(value->key_block != NULL)
5748 {
5749 kmip_free_key_block(ctx, value->key_block);
5750 ctx->free_func(ctx->state, value->key_block);
5751 value->key_block = NULL;
5752 }
5753 }
5754
5755 return;
5756 }
5757
5758 void
5759 kmip_free_key_wrapping_specification(KMIP *ctx, KeyWrappingSpecification *value)
5760 {
5761 if(value != NULL)
5762 {
5763 if(value->encryption_key_info != NULL)
5764 {
5765 kmip_free_encryption_key_information(ctx, value->encryption_key_info);
5766 ctx->free_func(ctx->state, value->encryption_key_info);
5767 value->encryption_key_info = NULL;
5768 }
5769
5770 if(value->mac_signature_key_info != NULL)
5771 {
5772 kmip_free_mac_signature_key_information(ctx, value->mac_signature_key_info);
5773 ctx->free_func(ctx->state, value->mac_signature_key_info);
5774 value->mac_signature_key_info = NULL;
5775 }
5776
5777 if(value->attribute_names != NULL)
5778 {
5779 for(size_t i = 0; i < value->attribute_name_count; i++)
5780 {
5781 kmip_free_text_string(ctx, &value->attribute_names[i]);
5782 }
5783 ctx->free_func(ctx->state, value->attribute_names);
5784 value->attribute_names = NULL;
5785 }
5786 value->attribute_name_count = 0;
5787
5788 value->wrapping_method = 0;
5789 value->encoding_option = 0;
5790 }
5791
5792 return;
5793 }
5794
5795 void
5796 kmip_free_register_request_payload(KMIP *ctx, RegisterRequestPayload *value)
5797 {
5798 if(value != NULL)
5799 {
5800 if(value->template_attribute != NULL)
5801 {
5802 kmip_free_template_attribute(ctx, value->template_attribute);
5803 ctx->free_func(ctx->state, value->template_attribute);
5804 value->template_attribute = NULL;
5805 }
5806
5807 if(value->attributes != NULL)
5808 {
5809 kmip_free_attributes(ctx, value->attributes);
5810 ctx->free_func(ctx->state, value->attributes);
5811 value->attributes = NULL;
5812 }
5813
5814 if(value->protection_storage_masks != NULL)
5815 {
5816 kmip_free_protection_storage_masks(ctx, value->protection_storage_masks);
5817 ctx->free_func(ctx->state, value->protection_storage_masks);
5818 value->protection_storage_masks = NULL;
5819 }
5820
5821 value->object_type = 0;
5822 }
5823
5824 return;
5825 }
5826
5827 void
5828 kmip_free_create_request_payload(KMIP *ctx, CreateRequestPayload *value)
5829 {
5830 if(value != NULL)
5831 {
5832 if(value->template_attribute != NULL)
5833 {
5834 kmip_free_template_attribute(ctx, value->template_attribute);
5835 ctx->free_func(ctx->state, value->template_attribute);
5836 value->template_attribute = NULL;
5837 }
5838
5839 if(value->attributes != NULL)
5840 {
5841 kmip_free_attributes(ctx, value->attributes);
5842 ctx->free_func(ctx->state, value->attributes);
5843 value->attributes = NULL;
5844 }
5845
5846 if(value->protection_storage_masks != NULL)
5847 {
5848 kmip_free_protection_storage_masks(ctx, value->protection_storage_masks);
5849 ctx->free_func(ctx->state, value->protection_storage_masks);
5850 value->protection_storage_masks = NULL;
5851 }
5852
5853 value->object_type = 0;
5854 }
5855
5856 return;
5857 }
5858
5859 void
5860 kmip_free_create_response_payload(KMIP *ctx, CreateResponsePayload *value)
5861 {
5862 if(value != NULL)
5863 {
5864 if(value->unique_identifier != NULL)
5865 {
5866 kmip_free_text_string(ctx, value->unique_identifier);
5867 ctx->free_func(ctx->state, value->unique_identifier);
5868 value->unique_identifier = NULL;
5869 }
5870
5871 if(value->template_attribute != NULL)
5872 {
5873 kmip_free_template_attribute(ctx, value->template_attribute);
5874 ctx->free_func(ctx->state, value->template_attribute);
5875 value->template_attribute = NULL;
5876 }
5877
5878 value->object_type = 0;
5879 }
5880
5881 return;
5882 }
5883
5884 void
5885 kmip_free_register_response_payload(KMIP *ctx, RegisterResponsePayload *value)
5886 {
5887 if(value != NULL)
5888 {
5889 if(value->unique_identifier != NULL)
5890 {
5891 kmip_free_text_string(ctx, value->unique_identifier);
5892 ctx->free_func(ctx->state, value->unique_identifier);
5893 value->unique_identifier = NULL;
5894 }
5895
5896 if(value->template_attribute != NULL)
5897 {
5898 kmip_free_template_attribute(ctx, value->template_attribute);
5899 ctx->free_func(ctx->state, value->template_attribute);
5900 value->template_attribute = NULL;
5901 }
5902 }
5903
5904 return;
5905 }
5906
5907 void
5908 kmip_free_get_request_payload(KMIP *ctx, GetRequestPayload *value)
5909 {
5910 if(value != NULL)
5911 {
5912 if(value->unique_identifier != NULL)
5913 {
5914 kmip_free_text_string(ctx, value->unique_identifier);
5915 ctx->free_func(ctx->state, value->unique_identifier);
5916 value->unique_identifier = NULL;
5917 }
5918
5919 if(value->key_wrapping_spec != NULL)
5920 {
5921 kmip_free_key_wrapping_specification(ctx, value->key_wrapping_spec);
5922 ctx->free_func(ctx->state, value->key_wrapping_spec);
5923 value->key_wrapping_spec = NULL;
5924 }
5925
5926 value->key_format_type = 0;
5927 value->key_compression_type = 0;
5928 value->key_wrap_type = 0;
5929 }
5930
5931 return;
5932 }
5933
5934 void
5935 kmip_free_get_attribute_request_payload(KMIP *ctx, GetAttributeRequestPayload *value)
5936 {
5937 if(value != NULL)
5938 {
5939 if(value->unique_identifier != NULL)
5940 {
5941 kmip_free_text_string(ctx, value->unique_identifier);
5942 ctx->free_func(ctx->state, value->unique_identifier);
5943 value->unique_identifier = NULL;
5944 }
5945 if(value->attribute_name != NULL)
5946 {
5947 kmip_free_text_string(ctx, value->attribute_name);
5948 ctx->free_func(ctx->state, value->attribute_name);
5949 value->attribute_name = NULL;
5950 }
5951
5952 }
5953
5954 return;
5955 }
5956
5957 void
5958 kmip_free_get_response_payload(KMIP *ctx, GetResponsePayload *value)
5959 {
5960 if(value != NULL)
5961 {
5962 if(value->unique_identifier != NULL)
5963 {
5964 kmip_free_text_string(ctx, value->unique_identifier);
5965 ctx->free_func(ctx->state, value->unique_identifier);
5966 value->unique_identifier = NULL;
5967 }
5968
5969 if(value->object != NULL)
5970 {
5971 switch(value->object_type)
5972 {
5973 case KMIP_OBJTYPE_SYMMETRIC_KEY:
5974 kmip_free_symmetric_key(ctx, (SymmetricKey *)value->object);
5975 break;
5976
5977 case KMIP_OBJTYPE_PUBLIC_KEY:
5978 kmip_free_public_key(ctx, (PublicKey *)value->object);
5979 break;
5980
5981 case KMIP_OBJTYPE_PRIVATE_KEY:
5982 kmip_free_private_key(ctx, (PrivateKey *)value->object);
5983 break;
5984
5985 default:
5986 /* NOTE (ph) Hitting this case means that we don't know */
5987 /* what the actual type, size, or value of */
5988 /* value->object is. We can still free it but we */
5989 /* cannot securely zero the memory. We also do not */
5990 /* know how to free any possible substructures */
5991 /* pointed to within value->object. */
5992 /* */
5993 /* Avoid hitting this case at all costs. */
5994 break;
5995 };
5996
5997 ctx->free_func(ctx->state, value->object);
5998 value->object = NULL;
5999 }
6000
6001 value->object_type = 0;
6002 }
6003
6004 return;
6005 }
6006
6007 void
6008 kmip_free_get_attribute_response_payload(KMIP *ctx, GetAttributeResponsePayload *value)
6009 {
6010 if(value != NULL)
6011 {
6012 if(value->unique_identifier != NULL)
6013 {
6014 kmip_free_text_string(ctx, value->unique_identifier);
6015 ctx->free_func(ctx->state, value->unique_identifier);
6016 value->unique_identifier = NULL;
6017 }
6018
6019 if(value->attribute != NULL)
6020 {
6021 kmip_free_attribute(ctx, value->attribute);
6022 ctx->free_func(ctx->state, value->attribute);
6023 value->attribute = NULL;
6024 }
6025
6026 }
6027
6028 return;
6029 }
6030 void
6031 kmip_free_destroy_request_payload(KMIP *ctx, DestroyRequestPayload *value)
6032 {
6033 if(value != NULL)
6034 {
6035 if(value->unique_identifier != NULL)
6036 {
6037 kmip_free_text_string(ctx, value->unique_identifier);
6038 ctx->free_func(ctx->state, value->unique_identifier);
6039 value->unique_identifier = NULL;
6040 }
6041 }
6042
6043 return;
6044 }
6045
6046 void
6047 kmip_free_destroy_response_payload(KMIP *ctx, DestroyResponsePayload *value)
6048 {
6049 if(value != NULL)
6050 {
6051 if(value->unique_identifier != NULL)
6052 {
6053 kmip_free_text_string(ctx, value->unique_identifier);
6054 ctx->free_func(ctx->state, value->unique_identifier);
6055 value->unique_identifier = NULL;
6056 }
6057 }
6058
6059 return;
6060 }
6061
6062 void
6063 kmip_free_request_batch_item(KMIP *ctx, RequestBatchItem *value)
6064 {
6065 if(value != NULL)
6066 {
6067 if(value->unique_batch_item_id != NULL)
6068 {
6069 kmip_free_byte_string(ctx, value->unique_batch_item_id);
6070 ctx->free_func(ctx->state, value->unique_batch_item_id);
6071 value->unique_batch_item_id = NULL;
6072 }
6073
6074 if(value->request_payload != NULL)
6075 {
6076 switch(value->operation)
6077 {
6078 case KMIP_OP_CREATE:
6079 kmip_free_create_request_payload(ctx, (CreateRequestPayload *)value->request_payload);
6080 break;
6081
6082 case KMIP_OP_REGISTER:
6083 kmip_free_register_request_payload(ctx, (RegisterRequestPayload *)value->request_payload);
6084 break;
6085
6086 case KMIP_OP_GET:
6087 kmip_free_get_request_payload(ctx, (GetRequestPayload *)value->request_payload);
6088 break;
6089
6090 case KMIP_OP_GET_ATTRIBUTES:
6091 kmip_free_get_attribute_request_payload(ctx, (GetAttributeRequestPayload *)value->request_payload);
6092 break;
6093
6094 case KMIP_OP_DESTROY:
6095 kmip_free_destroy_request_payload(ctx, (DestroyRequestPayload *)value->request_payload);
6096 break;
6097
6098 case KMIP_OP_QUERY:
6099 kmip_free_query_request_payload(ctx, (QueryRequestPayload *)value->request_payload);
6100 break;
6101
6102 case KMIP_OP_LOCATE:
6103 kmip_free_locate_request_payload(ctx, (LocateRequestPayload *)value->request_payload);
6104 break;
6105
6106 default:
6107 /* NOTE (ph) Hitting this case means that we don't know */
6108 /* what the actual type, size, or value of */
6109 /* value->request_payload is. We can still free it */
6110 /* but we cannot securely zero the memory. We also */
6111 /* do not know how to free any possible substructures */
6112 /* pointed to within value->request_payload. */
6113 /* */
6114 /* Avoid hitting this case at all costs. */
6115 break;
6116 };
6117
6118 ctx->free_func(ctx->state, value->request_payload);
6119 value->request_payload = NULL;
6120 }
6121
6122 value->operation = 0;
6123 value->ephemeral = 0;
6124 }
6125
6126 return;
6127 }
6128
6129 void
6130 kmip_free_response_batch_item(KMIP *ctx, ResponseBatchItem *value)
6131 {
6132 if(value != NULL)
6133 {
6134 if(value->unique_batch_item_id != NULL)
6135 {
6136 kmip_free_byte_string(ctx, value->unique_batch_item_id);
6137 ctx->free_func(ctx->state, value->unique_batch_item_id);
6138 value->unique_batch_item_id = NULL;
6139 }
6140
6141 if(value->result_message != NULL)
6142 {
6143 kmip_free_text_string(ctx, value->result_message);
6144 ctx->free_func(ctx->state, value->result_message);
6145 value->result_message = NULL;
6146 }
6147
6148 if(value->asynchronous_correlation_value != NULL)
6149 {
6150 kmip_free_byte_string(ctx, value->asynchronous_correlation_value);
6151 ctx->free_func(ctx->state, value->asynchronous_correlation_value);
6152 value->asynchronous_correlation_value = NULL;
6153 }
6154
6155 if(value->response_payload != NULL)
6156 {
6157 switch(value->operation)
6158 {
6159 case KMIP_OP_CREATE:
6160 kmip_free_create_response_payload(ctx, (CreateResponsePayload *)value->response_payload);
6161 break;
6162
6163 case KMIP_OP_REGISTER:
6164 kmip_free_register_response_payload(ctx, (RegisterResponsePayload *)value->response_payload);
6165 break;
6166
6167 case KMIP_OP_GET:
6168 kmip_free_get_response_payload(ctx, (GetResponsePayload *)value->response_payload);
6169 break;
6170
6171 case KMIP_OP_GET_ATTRIBUTES:
6172 kmip_free_get_attribute_response_payload(ctx, (GetAttributeResponsePayload *)value->response_payload);
6173 break;
6174
6175 case KMIP_OP_DESTROY:
6176 kmip_free_destroy_response_payload(ctx, (DestroyResponsePayload *)value->response_payload);
6177 break;
6178
6179 case KMIP_OP_QUERY:
6180 kmip_free_query_response_payload(ctx, (QueryResponsePayload *)value->response_payload);
6181 break;
6182
6183 case KMIP_OP_LOCATE:
6184 kmip_free_locate_response_payload(ctx, (LocateResponsePayload *)value->response_payload);
6185 break;
6186
6187 default:
6188 /* NOTE (ph) Hitting this case means that we don't know */
6189 /* what the actual type, size, or value of */
6190 /* value->response_payload is. We can still free it */
6191 /* but we cannot securely zero the memory. We also */
6192 /* do not know how to free any possible substructures */
6193 /* pointed to within value->response_payload. */
6194 /* */
6195 /* Avoid hitting this case at all costs. */
6196 break;
6197 };
6198
6199 ctx->free_func(ctx->state, value->response_payload);
6200 value->response_payload = NULL;
6201 }
6202
6203 value->operation = 0;
6204 value->result_status = 0;
6205 value->result_reason = 0;
6206 }
6207
6208 return;
6209 }
6210
6211 void
6212 kmip_free_nonce(KMIP *ctx, Nonce *value)
6213 {
6214 if(value != NULL)
6215 {
6216 if(value->nonce_id != NULL)
6217 {
6218 kmip_free_byte_string(ctx, value->nonce_id);
6219 ctx->free_func(ctx->state, value->nonce_id);
6220 value->nonce_id = NULL;
6221 }
6222
6223 if(value->nonce_value != NULL)
6224 {
6225 kmip_free_byte_string(ctx, value->nonce_value);
6226 ctx->free_func(ctx->state, value->nonce_value);
6227 value->nonce_value = NULL;
6228 }
6229 }
6230
6231 return;
6232 }
6233
6234 void
6235 kmip_free_username_password_credential(KMIP *ctx, UsernamePasswordCredential *value)
6236 {
6237 if(value != NULL)
6238 {
6239 if(value->username != NULL)
6240 {
6241 kmip_free_text_string(ctx, value->username);
6242 ctx->free_func(ctx->state, value->username);
6243 value->username = NULL;
6244 }
6245
6246 if(value->password != NULL)
6247 {
6248 kmip_free_text_string(ctx, value->password);
6249 ctx->free_func(ctx->state, value->password);
6250 value->password = NULL;
6251 }
6252 }
6253
6254 return;
6255 }
6256
6257 void
6258 kmip_free_device_credential(KMIP *ctx, DeviceCredential *value)
6259 {
6260 if(value != NULL)
6261 {
6262 if(value->device_serial_number != NULL)
6263 {
6264 kmip_free_text_string(ctx, value->device_serial_number);
6265 ctx->free_func(ctx->state, value->device_serial_number);
6266 value->device_serial_number = NULL;
6267 }
6268
6269 if(value->password != NULL)
6270 {
6271 kmip_free_text_string(ctx, value->password);
6272 ctx->free_func(ctx->state, value->password);
6273 value->password = NULL;
6274 }
6275
6276 if(value->device_identifier != NULL)
6277 {
6278 kmip_free_text_string(ctx, value->device_identifier);
6279 ctx->free_func(ctx->state, value->device_identifier);
6280 value->device_identifier = NULL;
6281 }
6282
6283 if(value->network_identifier != NULL)
6284 {
6285 kmip_free_text_string(ctx, value->network_identifier);
6286 ctx->free_func(ctx->state, value->network_identifier);
6287 value->network_identifier = NULL;
6288 }
6289
6290 if(value->machine_identifier != NULL)
6291 {
6292 kmip_free_text_string(ctx, value->machine_identifier);
6293 ctx->free_func(ctx->state, value->machine_identifier);
6294 value->machine_identifier = NULL;
6295 }
6296
6297 if(value->media_identifier != NULL)
6298 {
6299 kmip_free_text_string(ctx, value->media_identifier);
6300 ctx->free_func(ctx->state, value->media_identifier);
6301 value->media_identifier = NULL;
6302 }
6303 }
6304
6305 return;
6306 }
6307
6308 void
6309 kmip_free_attestation_credential(KMIP *ctx, AttestationCredential *value)
6310 {
6311 if(value != NULL)
6312 {
6313 if(value->nonce != NULL)
6314 {
6315 kmip_free_nonce(ctx, value->nonce);
6316 ctx->free_func(ctx->state, value->nonce);
6317 value->nonce = NULL;
6318 }
6319
6320 if(value->attestation_measurement != NULL)
6321 {
6322 kmip_free_byte_string(ctx, value->attestation_measurement);
6323 ctx->free_func(ctx->state, value->attestation_measurement);
6324 value->attestation_measurement = NULL;
6325 }
6326
6327 if(value->attestation_assertion != NULL)
6328 {
6329 kmip_free_byte_string(ctx, value->attestation_assertion);
6330 ctx->free_func(ctx->state, value->attestation_assertion);
6331 value->attestation_assertion = NULL;
6332 }
6333
6334 value->attestation_type = 0;
6335 }
6336
6337 return;
6338 }
6339
6340 void
6341 kmip_free_credential_value(KMIP *ctx, enum credential_type type, void **value)
6342 {
6343 if(value != NULL)
6344 {
6345 if(*value != NULL)
6346 {
6347 switch(type)
6348 {
6349 case KMIP_CRED_USERNAME_AND_PASSWORD:
6350 kmip_free_username_password_credential(ctx, (UsernamePasswordCredential *)*value);
6351 break;
6352
6353 case KMIP_CRED_DEVICE:
6354 kmip_free_device_credential(ctx, (DeviceCredential *)*value);
6355 break;
6356
6357 case KMIP_CRED_ATTESTATION:
6358 kmip_free_attestation_credential(ctx, (AttestationCredential *)*value);
6359 break;
6360
6361 default:
6362 /* NOTE (ph) Hitting this case means that we don't know */
6363 /* what the actual type, size, or value of value is. */
6364 /* We can still free it but we cannot securely zero */
6365 /* the memory. We also do not know how to free any */
6366 /* possible substructures pointed to within value. */
6367 /* */
6368 /* Avoid hitting this case at all costs. */
6369 break;
6370 };
6371
6372 ctx->free_func(ctx->state, *value);
6373 *value = NULL;
6374 }
6375 }
6376
6377 return;
6378 }
6379
6380 void
6381 kmip_free_credential(KMIP *ctx, Credential *value)
6382 {
6383 if(value != NULL)
6384 {
6385 if(value->credential_value != NULL)
6386 {
6387 kmip_free_credential_value(ctx, value->credential_type, &value->credential_value);
6388 value->credential_value = NULL;
6389 }
6390
6391 value->credential_type = 0;
6392 }
6393
6394 return;
6395 }
6396
6397 void
6398 kmip_free_authentication(KMIP *ctx, Authentication *value)
6399 {
6400 if(value != NULL)
6401 {
6402 if(value->credential != NULL)
6403 {
6404 kmip_free_credential(ctx, value->credential);
6405 ctx->free_func(ctx->state, value->credential);
6406 value->credential = NULL;
6407 }
6408 }
6409
6410 return;
6411 }
6412
6413 void
6414 kmip_free_request_header(KMIP *ctx, RequestHeader *value)
6415 {
6416 if(value != NULL)
6417 {
6418 if(value->protocol_version != NULL)
6419 {
6420 ctx->memset_func(
6421 value->protocol_version,
6422 0,
6423 sizeof(ProtocolVersion));
6424 ctx->free_func(ctx->state, value->protocol_version);
6425 value->protocol_version = NULL;
6426 }
6427
6428 if(value->authentication != NULL)
6429 {
6430 kmip_free_authentication(ctx, value->authentication);
6431 ctx->free_func(ctx->state, value->authentication);
6432 value->authentication = NULL;
6433 }
6434
6435 if(value->attestation_types != NULL)
6436 {
6437 ctx->memset_func(
6438 value->attestation_types,
6439 0,
6440 value->attestation_type_count * sizeof(enum attestation_type));
6441 ctx->free_func(ctx->state, value->attestation_types);
6442 value->attestation_types = NULL;
6443 value->attestation_type_count = 0;
6444 }
6445
6446 if(value->client_correlation_value != NULL)
6447 {
6448 kmip_free_text_string(ctx, value->client_correlation_value);
6449 ctx->free_func(ctx->state, value->client_correlation_value);
6450 value->client_correlation_value = NULL;
6451 }
6452
6453 if(value->server_correlation_value != NULL)
6454 {
6455 kmip_free_text_string(ctx, value->server_correlation_value);
6456 ctx->free_func(ctx->state, value->server_correlation_value);
6457 value->server_correlation_value = NULL;
6458 }
6459
6460 kmip_init_request_header(value);
6461 }
6462
6463 return;
6464 }
6465
6466 void
6467 kmip_free_response_header(KMIP *ctx, ResponseHeader *value)
6468 {
6469 if(value != NULL)
6470 {
6471 if(value->protocol_version != NULL)
6472 {
6473 ctx->memset_func(
6474 value->protocol_version,
6475 0,
6476 sizeof(ProtocolVersion));
6477 ctx->free_func(ctx->state, value->protocol_version);
6478 value->protocol_version = NULL;
6479 }
6480
6481 if(value->nonce != NULL)
6482 {
6483 kmip_free_nonce(ctx, value->nonce);
6484 ctx->free_func(ctx->state, value->nonce);
6485 value->nonce = NULL;
6486 }
6487
6488 if(value->server_hashed_password != NULL)
6489 {
6490 kmip_free_byte_string(ctx, value->server_hashed_password);
6491 ctx->free_func(ctx->state, value->server_hashed_password);
6492 value->server_hashed_password = NULL;
6493 }
6494
6495 if(value->attestation_types != NULL)
6496 {
6497 ctx->memset_func(
6498 value->attestation_types,
6499 0,
6500 value->attestation_type_count * sizeof(enum attestation_type));
6501 ctx->free_func(ctx->state, value->attestation_types);
6502 value->attestation_types = NULL;
6503 }
6504
6505 value->attestation_type_count = 0;
6506
6507 if(value->client_correlation_value != NULL)
6508 {
6509 kmip_free_text_string(ctx, value->client_correlation_value);
6510 ctx->free_func(ctx->state, value->client_correlation_value);
6511 value->client_correlation_value = NULL;
6512 }
6513
6514 if(value->server_correlation_value != NULL)
6515 {
6516 kmip_free_text_string(ctx, value->server_correlation_value);
6517 ctx->free_func(ctx->state, value->server_correlation_value);
6518 value->server_correlation_value = NULL;
6519 }
6520
6521 kmip_init_response_header(value);
6522 }
6523
6524 return;
6525 }
6526
6527 void
6528 kmip_free_request_message(KMIP *ctx, RequestMessage *value)
6529 {
6530 if(value != NULL)
6531 {
6532 if(value->request_header != NULL)
6533 {
6534 kmip_free_request_header(ctx, value->request_header);
6535 ctx->free_func(ctx->state, value->request_header);
6536 value->request_header = NULL;
6537 }
6538
6539 if(value->batch_items != NULL)
6540 {
6541 for(size_t i = 0; i < value->batch_count; i++)
6542 {
6543 kmip_free_request_batch_item(ctx, &value->batch_items[i]);
6544 }
6545 ctx->free_func(ctx, value->batch_items);
6546 value->batch_items = NULL;
6547 }
6548
6549 value->batch_count = 0;
6550 }
6551
6552 return;
6553 }
6554
6555 void
6556 kmip_free_response_message(KMIP *ctx, ResponseMessage *value)
6557 {
6558 if(value != NULL)
6559 {
6560 if(value->response_header != NULL)
6561 {
6562 kmip_free_response_header(ctx, value->response_header);
6563 ctx->free_func(ctx->state, value->response_header);
6564 value->response_header = NULL;
6565 }
6566
6567 if(value->batch_items != NULL)
6568 {
6569 for(size_t i = 0; i < value->batch_count; i++)
6570 {
6571 kmip_free_response_batch_item(ctx, &value->batch_items[i]);
6572 }
6573 ctx->free_func(ctx, value->batch_items);
6574 value->batch_items = NULL;
6575 }
6576
6577 value->batch_count = 0;
6578 }
6579
6580 return;
6581 }
6582
6583 void
6584 kmip_free_query_functions(KMIP *ctx, Functions* value)
6585 {
6586 if (value != NULL)
6587 {
6588 if (value->function_list != NULL)
6589 {
6590 LinkedListItem *curr = kmip_linked_list_pop(value->function_list);
6591 while(curr != NULL)
6592 {
6593 ctx->free_func(ctx->state, curr->data);
6594 curr->data = NULL;
6595 ctx->free_func(ctx->state, curr);
6596 curr = kmip_linked_list_pop(value->function_list);
6597 }
6598 ctx->free_func(ctx->state, value->function_list);
6599 value->function_list = NULL;
6600 }
6601 }
6602
6603 return;
6604 }
6605
6606 void
6607 kmip_free_query_response_payload(KMIP *ctx, QueryResponsePayload *value)
6608 {
6609 if (value->operations)
6610 {
6611 kmip_free_operations(ctx, value->operations);
6612 ctx->free_func(ctx->state, value->operations);
6613 value->operations = NULL;
6614 }
6615 if (value->objects)
6616 {
6617 kmip_free_objects(ctx, value->objects);
6618 ctx->free_func(ctx->state, value->objects);
6619 value->objects = NULL;
6620 }
6621
6622 if (value->vendor_identification)
6623 {
6624 kmip_free_text_string(ctx, value->vendor_identification);
6625 ctx->free_func(ctx->state, value->vendor_identification);
6626 value->vendor_identification = NULL;
6627 }
6628
6629 if (value->server_information)
6630 {
6631 kmip_free_server_information(ctx, value->server_information);
6632 ctx->free_func(ctx->state, value->server_information);
6633 value->server_information = NULL;
6634 }
6635 }
6636
6637
6638 void
6639 kmip_free_query_request_payload(KMIP *ctx, QueryRequestPayload *value)
6640 {
6641 if(ctx == NULL || value == NULL)
6642 {
6643 return;
6644 }
6645
6646 if (value->functions != NULL)
6647 {
6648 kmip_free_query_functions(ctx, value->functions);
6649 ctx->free_func(ctx->state, value->functions);
6650 value->functions = NULL;
6651 }
6652 }
6653
6654 void
6655 kmip_free_operations(KMIP *ctx, Operations *value)
6656 {
6657
6658 if(value != NULL)
6659 {
6660 if(value->operation_list != NULL)
6661 {
6662 LinkedListItem *curr = kmip_linked_list_pop(value->operation_list);
6663 while(curr != NULL)
6664 {
6665 ctx->free_func(ctx->state, curr->data);
6666 curr->data = NULL;
6667 ctx->free_func(ctx->state, curr);
6668 curr = kmip_linked_list_pop(value->operation_list);
6669 }
6670 ctx->free_func(ctx->state, value->operation_list);
6671 value->operation_list = NULL;
6672 }
6673 }
6674
6675 return;
6676 }
6677 void
6678 kmip_free_objects(KMIP *ctx, ObjectTypes* value)
6679 {
6680 if(value != NULL)
6681 {
6682 if(value->object_list != NULL)
6683 {
6684 LinkedListItem *curr = kmip_linked_list_pop(value->object_list);
6685 while(curr != NULL)
6686 {
6687 ctx->free_func(ctx->state, curr->data);
6688 curr->data = NULL;
6689 ctx->free_func(ctx->state, curr);
6690 curr = kmip_linked_list_pop(value->object_list);
6691 }
6692 ctx->free_func(ctx->state, value->object_list);
6693 value->object_list = NULL;
6694 }
6695 }
6696
6697 return;
6698 }
6699
6700
6701 void
6702 kmip_free_server_information(KMIP* ctx, ServerInformation* value)
6703 {
6704 kmip_free_text_string(ctx, value->server_name);
6705 kmip_free_text_string(ctx, value->server_serial_number);
6706 kmip_free_text_string(ctx, value->server_version);
6707 kmip_free_text_string(ctx, value->server_load);
6708 kmip_free_text_string(ctx, value->product_name);
6709 kmip_free_text_string(ctx, value->build_level);
6710 kmip_free_text_string(ctx, value->build_date);
6711 kmip_free_text_string(ctx, value->cluster_info);
6712 }
6713
6714 /*
6715 Copying Functions
6716 */
6717
6718 int32 *
6719 kmip_deep_copy_int32(KMIP *ctx, const int32 *value)
6720 {
6721 if(ctx == NULL || value == NULL)
6722 return(NULL);
6723
6724 int32 *copy = ctx->calloc_func(ctx, 1, sizeof(int32));
6725 if(copy == NULL)
6726 return(NULL);
6727
6728 copy = ctx->memcpy_func(ctx->state, copy, value, sizeof(int32));
6729 return(copy);
6730 }
6731
6732 int64 *
6733 kmip_deep_copy_int64(KMIP *ctx, const int64 *value)
6734 {
6735 if(ctx == NULL || value == NULL)
6736 {
6737 return(NULL);
6738 }
6739
6740 int64 *copy = ctx->calloc_func(ctx->state, 1, sizeof(int64));
6741 if(copy == NULL)
6742 {
6743 return(NULL);
6744 }
6745
6746 copy = ctx->memcpy_func(ctx->state, copy, value, sizeof(int64));
6747 return(copy);
6748 }
6749
6750 TextString *
6751 kmip_deep_copy_text_string(KMIP *ctx, const TextString *value)
6752 {
6753 if(ctx == NULL || value == NULL)
6754 return(NULL);
6755
6756 TextString *copy = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
6757 if(copy == NULL)
6758 return(NULL);
6759
6760 copy->size = value->size;
6761 if(value->value != NULL)
6762 {
6763 copy->value = ctx->calloc_func(ctx->state, 1, value->size);
6764 if(copy->value == NULL && value->value != NULL)
6765 {
6766 ctx->free_func(ctx->state, copy);
6767 return(NULL);
6768 }
6769 copy->value = ctx->memcpy_func(ctx->state, copy->value, value->value, value->size);
6770 }
6771 else
6772 copy->value = NULL;
6773
6774 return(copy);
6775 }
6776
6777 ByteString *
6778 kmip_deep_copy_byte_string(KMIP *ctx, const ByteString *value)
6779 {
6780 if(NULL == ctx || NULL == value)
6781 {
6782 return(NULL);
6783 }
6784
6785 ByteString *copy = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
6786 if(NULL == copy)
6787 {
6788 return(NULL);
6789 }
6790
6791 copy->size = value->size;
6792 if(NULL != value->value)
6793 {
6794 copy->value = ctx->calloc_func(ctx->state, 1, value->size);
6795 if(NULL == copy->value)
6796 {
6797 ctx->free_func(ctx->state, copy);
6798 return(NULL);
6799 }
6800 copy->value = ctx->memcpy_func(ctx->state, copy->value, value->value, value->size);
6801 }
6802 else
6803 {
6804 copy->value = NULL;
6805 }
6806
6807 return(copy);
6808 }
6809
6810 Name *
6811 kmip_deep_copy_name(KMIP *ctx, const Name *value)
6812 {
6813 if(ctx == NULL || value == NULL)
6814 return(NULL);
6815
6816 Name *copy = ctx->calloc_func(ctx->state, 1, sizeof(Name));
6817 if(copy == NULL)
6818 return(NULL);
6819
6820 copy->type = value->type;
6821 if(value->value != NULL)
6822 {
6823 copy->value = kmip_deep_copy_text_string(ctx, value->value);
6824 if(copy->value == NULL)
6825 {
6826 ctx->free_func(ctx->state, copy);
6827 return(NULL);
6828 }
6829 }
6830 else
6831 copy->value = NULL;
6832
6833 return(copy);
6834 }
6835
6836 CryptographicParameters *
6837 kmip_deep_copy_cryptographic_parameters(KMIP *ctx, const CryptographicParameters *value)
6838 {
6839 if(NULL == ctx || NULL == value)
6840 {
6841 return(NULL);
6842 }
6843
6844 CryptographicParameters *copy = ctx->calloc_func(ctx->state, 1, sizeof(CryptographicParameters));
6845 if(NULL == copy)
6846 {
6847 return(NULL);
6848 }
6849
6850 if(NULL != value->p_source)
6851 {
6852 copy->p_source = kmip_deep_copy_byte_string(ctx, value->p_source);
6853 if(NULL == copy->p_source)
6854 {
6855 kmip_free_cryptographic_parameters(ctx, copy);
6856 ctx->free_func(ctx->state, copy);
6857 return(NULL);
6858 }
6859 }
6860 else
6861 {
6862 copy->p_source = NULL;
6863 }
6864
6865 copy->block_cipher_mode = value->block_cipher_mode;
6866 copy->padding_method = value->padding_method;
6867 copy->hashing_algorithm = value->hashing_algorithm;
6868 copy->key_role_type = value->key_role_type;
6869
6870 copy->digital_signature_algorithm = value->digital_signature_algorithm;
6871 copy->cryptographic_algorithm = value->cryptographic_algorithm;
6872 copy->random_iv = value->random_iv;
6873 copy->iv_length = value->iv_length;
6874 copy->tag_length = value->tag_length;
6875 copy->fixed_field_length = value->fixed_field_length;
6876 copy->invocation_field_length = value->invocation_field_length;
6877 copy->counter_length = value->counter_length;
6878 copy->initial_counter_value = value->initial_counter_value;
6879
6880 copy->salt_length = value->salt_length;
6881 copy->mask_generator = value->mask_generator;
6882 copy->mask_generator_hashing_algorithm = value->mask_generator_hashing_algorithm;
6883 copy->trailer_field = value->trailer_field;
6884
6885 return(copy);
6886 }
6887
6888 ApplicationSpecificInformation *
6889 kmip_deep_copy_application_specific_information(KMIP *ctx, const ApplicationSpecificInformation *value)
6890 {
6891 if(ctx == NULL || value == NULL)
6892 {
6893 return(NULL);
6894 }
6895
6896 ApplicationSpecificInformation *copy = ctx->calloc_func(ctx->state, 1, sizeof(ApplicationSpecificInformation));
6897 if(copy == NULL)
6898 {
6899 return(NULL);
6900 }
6901
6902 if(value->application_namespace != NULL)
6903 {
6904 copy->application_namespace = kmip_deep_copy_text_string(ctx, value->application_namespace);
6905 if(copy->application_namespace == NULL)
6906 {
6907 ctx->free_func(ctx->state, copy);
6908 return(NULL);
6909 }
6910 }
6911 else
6912 {
6913 copy->application_namespace = NULL;
6914 }
6915
6916 if(value->application_data != NULL)
6917 {
6918 copy->application_data = kmip_deep_copy_text_string(ctx, value->application_data);
6919 if(copy->application_data == NULL)
6920 {
6921 kmip_free_application_specific_information(ctx, copy);
6922 ctx->free_func(ctx->state, copy);
6923 return(NULL);
6924 }
6925 }
6926 else
6927 {
6928 copy->application_data = NULL;
6929 }
6930
6931 return(copy);
6932 }
6933
6934 Attribute *
6935 kmip_deep_copy_attribute(KMIP *ctx, const Attribute *value)
6936 {
6937 if(ctx == NULL || value == NULL)
6938 return(NULL);
6939
6940 Attribute *copy = ctx->calloc_func(ctx->state, 1, sizeof(Attribute));
6941 if(copy == NULL)
6942 return(NULL);
6943
6944 copy->type = value->type;
6945 copy->index = value->index;
6946
6947 if(value->value == NULL)
6948 {
6949 copy->value = NULL;
6950 return(copy);
6951 }
6952
6953 switch(value->type)
6954 {
6955 case KMIP_ATTR_UNIQUE_IDENTIFIER:
6956 case KMIP_ATTR_OPERATION_POLICY_NAME:
6957 case KMIP_ATTR_OBJECT_GROUP:
6958 {
6959 copy->value = kmip_deep_copy_text_string(ctx, (TextString *)value->value);
6960 if(copy->value == NULL)
6961 {
6962 ctx->free_func(ctx->state, copy);
6963 return(NULL);
6964 }
6965 } break;
6966
6967 case KMIP_ATTR_NAME:
6968 {
6969 copy->value = kmip_deep_copy_name(ctx, (Name *)value->value);
6970 if(copy->value == NULL)
6971 {
6972 ctx->free_func(ctx->state, copy);
6973 return(NULL);
6974 }
6975 } break;
6976
6977 case KMIP_ATTR_OBJECT_TYPE:
6978 case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
6979 case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
6980 case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
6981 case KMIP_ATTR_STATE:
6982 {
6983 copy->value = kmip_deep_copy_int32(ctx, (int32 *)value->value);
6984 if(copy->value == NULL)
6985 {
6986 ctx->free_func(ctx->state, copy);
6987 return(NULL);
6988 }
6989 } break;
6990
6991 case KMIP_ATTR_ACTIVATION_DATE:
6992 case KMIP_ATTR_DEACTIVATION_DATE:
6993 case KMIP_ATTR_PROCESS_START_DATE:
6994 case KMIP_ATTR_PROTECT_STOP_DATE:
6995 {
6996 copy->value = kmip_deep_copy_int64(ctx, (int64 *)value->value);
6997 if(copy->value == NULL)
6998 {
6999 ctx->free_func(ctx->state, copy);
7000 return(NULL);
7001 }
7002 } break;
7003
7004 case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
7005 {
7006 copy->value = kmip_deep_copy_cryptographic_parameters(ctx, (CryptographicParameters*)value->value);
7007 if(NULL == copy->value)
7008 {
7009 ctx->free_func(ctx->state, copy);
7010 return(NULL);
7011 }
7012 } break;
7013
7014 default:
7015 {
7016 ctx->free_func(ctx->state, copy);
7017 return(NULL);
7018 } break;
7019 };
7020
7021 return(copy);
7022 }
7023
7024 char*
7025 kmip_copy_textstring(char* dest, TextString* src, size_t size)
7026 {
7027 if(src && src->value != NULL)
7028 {
7029 size_t len = KMIP_MIN(size, src->size);
7030 memcpy(dest, src->value, len);
7031 dest[len] = 0;
7032 }
7033 else
7034 *dest = 0;
7035
7036 return dest;
7037 }
7038
7039 void
7040 kmip_copy_operations(int ops[], size_t* ops_size, Operations *value, unsigned max_ops)
7041 {
7042 if(value != NULL &&
7043 value->operation_list != NULL)
7044 {
7045 *ops_size = value->operation_list->size;
7046
7047 LinkedListItem *curr = value->operation_list->head;
7048 size_t idx = 0;
7049 while(curr != NULL && idx < max_ops )
7050 {
7051 ops[idx] = *(int32 *)curr->data;
7052 curr = curr->next;
7053 idx++;
7054 }
7055 }
7056 }
7057
7058 void
7059 kmip_copy_objects(int objs[], size_t* objs_size, ObjectTypes *value, unsigned max_objs)
7060 {
7061 if(value != NULL &&
7062 value->object_list != NULL)
7063 {
7064 *objs_size = value->object_list->size;
7065
7066 LinkedListItem *curr = value->object_list->head;
7067 size_t idx = 0;
7068 while(curr != NULL && idx < max_objs )
7069 {
7070 objs[idx] = *(int32 *)curr->data;
7071 curr = curr->next;
7072 idx++;
7073 }
7074 }
7075 }
7076
7077 void
7078 kmip_copy_query_result(QueryResponse* query_result, QueryResponsePayload *pld)
7079 {
7080 if(pld != NULL)
7081 {
7082 kmip_copy_operations(query_result->operations, &query_result->operations_size, pld->operations, MAX_QUERY_OPS);
7083 kmip_copy_objects(query_result->objects, &query_result->objects_size, pld->objects, MAX_QUERY_OBJS);
7084
7085 if(pld->vendor_identification)
7086 {
7087 kmip_copy_textstring(query_result->vendor_identification, pld->vendor_identification, sizeof(query_result->vendor_identification)-1);
7088 }
7089
7090 if(pld->server_information)
7091 {
7092 ServerInformation* srv = pld->server_information;
7093 query_result->server_information_valid = 1;
7094 kmip_copy_textstring(query_result->server_name, srv->server_name, MAX_QUERY_LEN-1);
7095 kmip_copy_textstring(query_result->server_serial_number, srv->server_serial_number, MAX_QUERY_LEN-1);
7096 kmip_copy_textstring(query_result->server_version, srv->server_version, MAX_QUERY_LEN-1);
7097 kmip_copy_textstring(query_result->server_load, srv->server_load, MAX_QUERY_LEN-1);
7098 kmip_copy_textstring(query_result->product_name, srv->product_name, MAX_QUERY_LEN-1);
7099 kmip_copy_textstring(query_result->build_level, srv->build_level, MAX_QUERY_LEN-1);
7100 kmip_copy_textstring(query_result->build_date, srv->build_date, MAX_QUERY_LEN-1);
7101 }
7102 }
7103 }
7104
7105
7106 /*
7107 Comparison Functions
7108 */
7109
7110 int
7111 kmip_compare_text_string(const TextString *a, const TextString *b)
7112 {
7113 if(a != b)
7114 {
7115 if((a == NULL) || (b == NULL))
7116 {
7117 return(KMIP_FALSE);
7118 }
7119
7120 if(a->size != b->size)
7121 {
7122 return(KMIP_FALSE);
7123 }
7124
7125 if(a->value != b->value)
7126 {
7127 if((a->value == NULL) || (b->value == NULL))
7128 {
7129 return(KMIP_FALSE);
7130 }
7131
7132 for(size_t i = 0; i < a->size; i++)
7133 {
7134 if(a->value[i] != b->value[i])
7135 {
7136 return(KMIP_FALSE);
7137 }
7138 }
7139 }
7140 }
7141
7142 return(KMIP_TRUE);
7143 }
7144
7145 int
7146 kmip_compare_byte_string(const ByteString *a, const ByteString *b)
7147 {
7148 if(a != b)
7149 {
7150 if((a == NULL) || (b == NULL))
7151 {
7152 return(KMIP_FALSE);
7153 }
7154
7155 if(a->size != b->size)
7156 {
7157 return(KMIP_FALSE);
7158 }
7159
7160 if(a->value != b->value)
7161 {
7162 if((a->value == NULL) || (b->value == NULL))
7163 {
7164 return(KMIP_FALSE);
7165 }
7166
7167 for(size_t i = 0; i < a->size; i++)
7168 {
7169 if(a->value[i] != b->value[i])
7170 {
7171 return(KMIP_FALSE);
7172 }
7173 }
7174 }
7175 }
7176
7177 return(KMIP_TRUE);
7178 }
7179
7180 int
7181 kmip_compare_name(const Name *a, const Name *b)
7182 {
7183 if(a != b)
7184 {
7185 if((a == NULL) || (b == NULL))
7186 {
7187 return(KMIP_FALSE);
7188 }
7189
7190 if(a->type != b->type)
7191 {
7192 return(KMIP_FALSE);
7193 }
7194
7195 if(a->value != b->value)
7196 {
7197 if((a->value == NULL) || (b->value == NULL))
7198 {
7199 return(KMIP_FALSE);
7200 }
7201
7202 if(kmip_compare_text_string(a->value, b->value) != KMIP_TRUE)
7203 {
7204 return(KMIP_FALSE);
7205 }
7206 }
7207 }
7208
7209 return(KMIP_TRUE);
7210 }
7211
7212 int
7213 kmip_compare_protection_storage_masks(const ProtectionStorageMasks *a, const ProtectionStorageMasks *b)
7214 {
7215 if(a != b)
7216 {
7217 if((a == NULL) || (b == NULL))
7218 {
7219 return(KMIP_FALSE);
7220 }
7221
7222 if((a->masks != b->masks))
7223 {
7224 if((a->masks == NULL) || (b->masks == NULL))
7225 {
7226 return(KMIP_FALSE);
7227 }
7228
7229 if((a->masks->size != b->masks->size))
7230 {
7231 return(KMIP_FALSE);
7232 }
7233
7234 LinkedListItem *a_item = a->masks->head;
7235 LinkedListItem *b_item = b->masks->head;
7236 while((a_item != NULL) && (b_item != NULL))
7237 {
7238 if(a_item != b_item)
7239 {
7240 int32 *a_data = (int32 *)a_item->data;
7241 int32 *b_data = (int32 *)b_item->data;
7242 if(a_data != b_data)
7243 {
7244 if((a_data == NULL) || (b_data == NULL))
7245 {
7246 return(KMIP_FALSE);
7247 }
7248 if(*a_data != *b_data)
7249 {
7250 return(KMIP_FALSE);
7251 }
7252 }
7253 }
7254
7255 a_item = a_item->next;
7256 b_item = b_item->next;
7257 }
7258
7259 if(a_item != b_item)
7260 {
7261 return(KMIP_FALSE);
7262 }
7263 }
7264 }
7265
7266 return(KMIP_TRUE);
7267 }
7268
7269 int
7270 kmip_compare_attribute(const Attribute *a, const Attribute *b)
7271 {
7272 if(a != b)
7273 {
7274 if((a == NULL) || (b == NULL))
7275 {
7276 return(KMIP_FALSE);
7277 }
7278
7279 if(a->type != b->type)
7280 {
7281 return(KMIP_FALSE);
7282 }
7283
7284 if(a->index != b->index)
7285 {
7286 return(KMIP_FALSE);
7287 }
7288
7289 if(a->value != b->value)
7290 {
7291 if((a->value == NULL) || (b->value == NULL))
7292 {
7293 return(KMIP_FALSE);
7294 }
7295
7296 switch(a->type)
7297 {
7298 case KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION:
7299 {
7300 return(
7301 kmip_compare_application_specific_information(
7302 (ApplicationSpecificInformation*)a->value,
7303 (ApplicationSpecificInformation*)b->value
7304 )
7305 );
7306 }
7307 break;
7308
7309 case KMIP_ATTR_UNIQUE_IDENTIFIER:
7310 return(kmip_compare_text_string((TextString *)a->value, (TextString *)b->value));
7311 break;
7312
7313 case KMIP_ATTR_NAME:
7314 return(kmip_compare_name((Name *)a->value, (Name *)b->value));
7315 break;
7316
7317 case KMIP_ATTR_OBJECT_TYPE:
7318 if(*(int32*)a->value != *(int32*)b->value)
7319 {
7320 return(KMIP_FALSE);
7321 }
7322 break;
7323
7324 case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
7325 if(*(int32*)a->value != *(int32*)b->value)
7326 {
7327 return(KMIP_FALSE);
7328 }
7329 break;
7330
7331 case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
7332 if(*(int32*)a->value != *(int32*)b->value)
7333 {
7334 return(KMIP_FALSE);
7335 }
7336 break;
7337
7338 case KMIP_ATTR_OPERATION_POLICY_NAME:
7339 return(kmip_compare_text_string((TextString *)a->value, (TextString *)b->value));
7340 break;
7341
7342 case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
7343 if(*(int32*)a->value != *(int32*)b->value)
7344 {
7345 return(KMIP_FALSE);
7346 }
7347 break;
7348
7349 case KMIP_ATTR_STATE:
7350 if(*(int32*)a->value != *(int32*)b->value)
7351 {
7352 return(KMIP_FALSE);
7353 }
7354 break;
7355
7356 case KMIP_ATTR_OBJECT_GROUP:
7357 {
7358 return(kmip_compare_text_string((TextString *)a->value, (TextString *)b->value));
7359 }
7360 break;
7361
7362 case KMIP_ATTR_ACTIVATION_DATE:
7363 case KMIP_ATTR_DEACTIVATION_DATE:
7364 case KMIP_ATTR_PROCESS_START_DATE:
7365 case KMIP_ATTR_PROTECT_STOP_DATE:
7366 {
7367 if(*(int64*)a->value != *(int64*)b->value)
7368 {
7369 return(KMIP_FALSE);
7370 }
7371 } break;
7372
7373 case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
7374 {
7375 return(kmip_compare_cryptographic_parameters(
7376 (CryptographicParameters*)a->value,
7377 (CryptographicParameters*)b->value
7378 ));
7379 } break;
7380
7381 default:
7382 /* NOTE (ph) Unsupported types can't be compared. */
7383 return(KMIP_FALSE);
7384 break;
7385 };
7386 }
7387 }
7388
7389 return(KMIP_TRUE);
7390 }
7391
7392 int
7393 kmip_compare_attributes(const Attributes *a, const Attributes *b)
7394 {
7395 if(a != b)
7396 {
7397 if((a == NULL) || (b == NULL))
7398 {
7399 return(KMIP_FALSE);
7400 }
7401
7402 if((a->attribute_list != b->attribute_list))
7403 {
7404 if((a->attribute_list == NULL) || (b->attribute_list == NULL))
7405 {
7406 return(KMIP_FALSE);
7407 }
7408
7409 if((a->attribute_list->size != b->attribute_list->size))
7410 {
7411 return(KMIP_FALSE);
7412 }
7413
7414 LinkedListItem *a_item = a->attribute_list->head;
7415 LinkedListItem *b_item = b->attribute_list->head;
7416 while((a_item != NULL) && (b_item != NULL))
7417 {
7418 if(a_item != b_item)
7419 {
7420 Attribute *a_data = (Attribute *)a_item->data;
7421 Attribute *b_data = (Attribute *)b_item->data;
7422 if(kmip_compare_attribute(a_data, b_data) == KMIP_FALSE)
7423 {
7424 return(KMIP_FALSE);
7425 }
7426 }
7427
7428 a_item = a_item->next;
7429 b_item = b_item->next;
7430 }
7431
7432 if(a_item != b_item)
7433 {
7434 return(KMIP_FALSE);
7435 }
7436 }
7437 }
7438
7439 return(KMIP_TRUE);
7440 }
7441
7442 int
7443 kmip_compare_template_attribute(const TemplateAttribute *a, const TemplateAttribute *b)
7444 {
7445 if(a != b)
7446 {
7447 if((a == NULL) || (b == NULL))
7448 {
7449 return(KMIP_FALSE);
7450 }
7451
7452 if(a->name_count != b->name_count)
7453 {
7454 return(KMIP_FALSE);
7455 }
7456
7457 if(a->attribute_count != b->attribute_count)
7458 {
7459 return(KMIP_FALSE);
7460 }
7461
7462 if(a->names != b->names)
7463 {
7464 if((a->names == NULL) || (b->names == NULL))
7465 {
7466 return(KMIP_FALSE);
7467 }
7468
7469 for(size_t i = 0; i < a->name_count; i++)
7470 {
7471 if(kmip_compare_name(&a->names[i], &b->names[i]) == KMIP_FALSE)
7472 {
7473 return(KMIP_FALSE);
7474 }
7475 }
7476 }
7477
7478 if(a->attributes != b->attributes)
7479 {
7480 if((a->attributes == NULL) || (b->attributes == NULL))
7481 {
7482 return(KMIP_FALSE);
7483 }
7484
7485 for(size_t i = 0; i < a->attribute_count; i++)
7486 {
7487 if(kmip_compare_attribute(&a->attributes[i], &b->attributes[i]) == KMIP_FALSE)
7488 {
7489 return(KMIP_FALSE);
7490 }
7491 }
7492 }
7493 }
7494
7495 return(KMIP_TRUE);
7496 }
7497
7498 int
7499 kmip_compare_protocol_version(const ProtocolVersion *a, const ProtocolVersion *b)
7500 {
7501 if(a != b)
7502 {
7503 if((a == NULL) || (b == NULL))
7504 {
7505 return(KMIP_FALSE);
7506 }
7507
7508 if(a->major != b->major)
7509 {
7510 return(KMIP_FALSE);
7511 }
7512
7513 if(a->minor != b->minor)
7514 {
7515 return(KMIP_FALSE);
7516 }
7517 }
7518
7519 return(KMIP_TRUE);
7520 }
7521
7522 int
7523 kmip_compare_transparent_symmetric_key(const TransparentSymmetricKey *a, const TransparentSymmetricKey *b)
7524 {
7525 if(a != b)
7526 {
7527 if((a == NULL) || (b == NULL))
7528 {
7529 return(KMIP_FALSE);
7530 }
7531
7532 if(a->key != b->key)
7533 {
7534 if((a->key == NULL) || (b->key == NULL))
7535 {
7536 return(KMIP_FALSE);
7537 }
7538
7539 if(kmip_compare_byte_string(a->key, b->key) == KMIP_FALSE)
7540 {
7541 return(KMIP_FALSE);
7542 }
7543 }
7544 }
7545
7546 return(KMIP_TRUE);
7547 }
7548
7549 int
7550 kmip_compare_key_material(enum key_format_type format, void **a, void **b)
7551 {
7552 if(a != b)
7553 {
7554 if((a == NULL) || (b == NULL))
7555 {
7556 return(KMIP_FALSE);
7557 }
7558
7559 if(*a != *b)
7560 {
7561 if((*a == NULL) || (*b == NULL))
7562 {
7563 return(KMIP_FALSE);
7564 }
7565
7566 switch(format)
7567 {
7568 case KMIP_KEYFORMAT_RAW:
7569 case KMIP_KEYFORMAT_OPAQUE:
7570 case KMIP_KEYFORMAT_PKCS1:
7571 case KMIP_KEYFORMAT_PKCS8:
7572 case KMIP_KEYFORMAT_X509:
7573 case KMIP_KEYFORMAT_EC_PRIVATE_KEY:
7574 if(kmip_compare_byte_string(*a, *b) == KMIP_FALSE)
7575 {
7576 return(KMIP_FALSE);
7577 }
7578 break;
7579
7580 case KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY:
7581 if(kmip_compare_transparent_symmetric_key(*a, *b) == KMIP_FALSE)
7582 {
7583 return(KMIP_FALSE);
7584 }
7585 break;
7586
7587 default:
7588 /* NOTE (ph) Unsupported types cannot be compared. */
7589 return(KMIP_FALSE);
7590 break;
7591 };
7592 }
7593 }
7594
7595 return(KMIP_TRUE);
7596 }
7597
7598 int
7599 kmip_compare_key_value(enum key_format_type format, const KeyValue *a, const KeyValue *b)
7600 {
7601 if(a != b)
7602 {
7603 if((a == NULL) || (b == NULL))
7604 {
7605 return(KMIP_FALSE);
7606 }
7607
7608 if(a->key_material != b->key_material)
7609 {
7610 if((a->key_material == NULL) || (b->key_material == NULL))
7611 {
7612 return(KMIP_FALSE);
7613 }
7614
7615 if(kmip_compare_key_material(format, (void**)&a->key_material, (void**)&b->key_material) == KMIP_FALSE)
7616 {
7617 return(KMIP_FALSE);
7618 }
7619 }
7620
7621 if(a->attributes != b->attributes)
7622 {
7623 if((a->attributes == NULL) || (b->attributes == NULL))
7624 {
7625 return(KMIP_FALSE);
7626 }
7627
7628 for(size_t i = 0; i < a->attribute_count; i++)
7629 {
7630 if(kmip_compare_attribute(&a->attributes[i], &b->attributes[i]) == KMIP_FALSE)
7631 {
7632 return(KMIP_FALSE);
7633 }
7634 }
7635 }
7636 }
7637
7638 return(KMIP_TRUE);
7639 }
7640
7641 int
7642 kmip_compare_application_specific_information(const ApplicationSpecificInformation *a, const ApplicationSpecificInformation *b)
7643 {
7644 if(a != b)
7645 {
7646 if((a == NULL) || (b == NULL))
7647 {
7648 return(KMIP_FALSE);
7649 }
7650
7651 if(a->application_namespace != b->application_namespace)
7652 {
7653 if((a->application_namespace == NULL) || (b->application_namespace == NULL))
7654 {
7655 return(KMIP_FALSE);
7656 }
7657
7658 if(kmip_compare_text_string(a->application_namespace, b->application_namespace) == KMIP_FALSE)
7659 {
7660 return(KMIP_FALSE);
7661 }
7662 }
7663
7664 if(a->application_data != b->application_data)
7665 {
7666 if((a->application_data == NULL) || (b->application_data == NULL))
7667 {
7668 return(KMIP_FALSE);
7669 }
7670
7671 if(kmip_compare_text_string(a->application_data, b->application_data) == KMIP_FALSE)
7672 {
7673 return(KMIP_FALSE);
7674 }
7675 }
7676 }
7677
7678 return(KMIP_TRUE);
7679 }
7680
7681 int
7682 kmip_compare_cryptographic_parameters(const CryptographicParameters *a, const CryptographicParameters *b)
7683 {
7684 if(a != b)
7685 {
7686 if((a == NULL) || (b == NULL))
7687 {
7688 return(KMIP_FALSE);
7689 }
7690
7691 if(a->block_cipher_mode != b->block_cipher_mode)
7692 {
7693 return(KMIP_FALSE);
7694 }
7695
7696 if(a->padding_method != b->padding_method)
7697 {
7698 return(KMIP_FALSE);
7699 }
7700
7701 if(a->hashing_algorithm != b->hashing_algorithm)
7702 {
7703 return(KMIP_FALSE);
7704 }
7705
7706 if(a->key_role_type != b->key_role_type)
7707 {
7708 return(KMIP_FALSE);
7709 }
7710
7711 if(a->digital_signature_algorithm != b->digital_signature_algorithm)
7712 {
7713 return(KMIP_FALSE);
7714 }
7715
7716 if(a->cryptographic_algorithm != b->cryptographic_algorithm)
7717 {
7718 return(KMIP_FALSE);
7719 }
7720
7721 if(a->random_iv != b->random_iv)
7722 {
7723 return(KMIP_FALSE);
7724 }
7725
7726 if(a->iv_length != b->iv_length)
7727 {
7728 return(KMIP_FALSE);
7729 }
7730
7731 if(a->tag_length != b->tag_length)
7732 {
7733 return(KMIP_FALSE);
7734 }
7735
7736 if(a->fixed_field_length != b->fixed_field_length)
7737 {
7738 return(KMIP_FALSE);
7739 }
7740
7741 if(a->invocation_field_length != b->invocation_field_length)
7742 {
7743 return(KMIP_FALSE);
7744 }
7745
7746 if(a->counter_length != b->counter_length)
7747 {
7748 return(KMIP_FALSE);
7749 }
7750
7751 if(a->initial_counter_value != b->initial_counter_value)
7752 {
7753 return(KMIP_FALSE);
7754 }
7755
7756 if(a->salt_length != b->salt_length)
7757 {
7758 return(KMIP_FALSE);
7759 }
7760
7761 if(a->mask_generator != b->mask_generator)
7762 {
7763 return(KMIP_FALSE);
7764 }
7765
7766 if(a->mask_generator_hashing_algorithm !=
7767 b->mask_generator_hashing_algorithm)
7768 {
7769 return(KMIP_FALSE);
7770 }
7771
7772 if(a->trailer_field != b->trailer_field)
7773 {
7774 return(KMIP_FALSE);
7775 }
7776
7777 if(a->p_source != b->p_source)
7778 {
7779 if((a->p_source == NULL) || (b->p_source == NULL))
7780 {
7781 return(KMIP_FALSE);
7782 }
7783
7784 if(kmip_compare_byte_string(a->p_source, b->p_source) == KMIP_FALSE)
7785 {
7786 return(KMIP_FALSE);
7787 }
7788 }
7789 }
7790
7791 return(KMIP_TRUE);
7792 }
7793
7794 int
7795 kmip_compare_encryption_key_information(const EncryptionKeyInformation *a, const EncryptionKeyInformation *b)
7796 {
7797 if(a != b)
7798 {
7799 if((a == NULL) || (b == NULL))
7800 {
7801 return(KMIP_FALSE);
7802 }
7803
7804 if(a->unique_identifier != b->unique_identifier)
7805 {
7806 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
7807 {
7808 return(KMIP_FALSE);
7809 }
7810
7811 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
7812 {
7813 return(KMIP_FALSE);
7814 }
7815 }
7816
7817 if(a->cryptographic_parameters != b->cryptographic_parameters)
7818 {
7819 if((a->cryptographic_parameters == NULL) ||
7820 (b->cryptographic_parameters == NULL))
7821 {
7822 return(KMIP_FALSE);
7823 }
7824
7825 if(kmip_compare_cryptographic_parameters(a->cryptographic_parameters, b->cryptographic_parameters) == KMIP_FALSE)
7826 {
7827 return(KMIP_FALSE);
7828 }
7829 }
7830 }
7831
7832 return(KMIP_TRUE);
7833 }
7834
7835 int
7836 kmip_compare_mac_signature_key_information(const MACSignatureKeyInformation *a, const MACSignatureKeyInformation *b)
7837 {
7838 if(a != b)
7839 {
7840 if((a == NULL) || (b == NULL))
7841 {
7842 return(KMIP_FALSE);
7843 }
7844
7845 if(a->unique_identifier != b->unique_identifier)
7846 {
7847 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
7848 {
7849 return(KMIP_FALSE);
7850 }
7851
7852 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
7853 {
7854 return(KMIP_FALSE);
7855 }
7856 }
7857
7858 if(a->cryptographic_parameters != b->cryptographic_parameters)
7859 {
7860 if((a->cryptographic_parameters == NULL) || (b->cryptographic_parameters == NULL))
7861 {
7862 return(KMIP_FALSE);
7863 }
7864
7865 if(kmip_compare_cryptographic_parameters(a->cryptographic_parameters, b->cryptographic_parameters) == KMIP_FALSE)
7866 {
7867 return(KMIP_FALSE);
7868 }
7869 }
7870 }
7871
7872 return(KMIP_TRUE);
7873 }
7874
7875 int
7876 kmip_compare_key_wrapping_data(const KeyWrappingData *a, const KeyWrappingData *b)
7877 {
7878 if(a != b)
7879 {
7880 if((a == NULL) || (b == NULL))
7881 {
7882 return(KMIP_FALSE);
7883 }
7884
7885 if(a->wrapping_method != b->wrapping_method)
7886 {
7887 return(KMIP_FALSE);
7888 }
7889
7890 if(a->encoding_option != b->encoding_option)
7891 {
7892 return(KMIP_FALSE);
7893 }
7894
7895 if(a->mac_signature != b->mac_signature)
7896 {
7897 if((a->mac_signature == NULL) || (b->mac_signature == NULL))
7898 {
7899 return(KMIP_FALSE);
7900 }
7901
7902 if(kmip_compare_byte_string(a->mac_signature, b->mac_signature) == KMIP_FALSE)
7903 {
7904 return(KMIP_FALSE);
7905 }
7906 }
7907
7908 if(a->iv_counter_nonce != b->iv_counter_nonce)
7909 {
7910 if((a->iv_counter_nonce == NULL) || (b->iv_counter_nonce == NULL))
7911 {
7912 return(KMIP_FALSE);
7913 }
7914
7915 if(kmip_compare_byte_string(a->iv_counter_nonce, b->iv_counter_nonce) == KMIP_FALSE)
7916 {
7917 return(KMIP_FALSE);
7918 }
7919 }
7920
7921 if(a->encryption_key_info != b->encryption_key_info)
7922 {
7923 if((a->encryption_key_info == NULL) || (b->encryption_key_info == NULL))
7924 {
7925 return(KMIP_FALSE);
7926 }
7927
7928 if(kmip_compare_encryption_key_information(a->encryption_key_info, b->encryption_key_info) == KMIP_FALSE)
7929 {
7930 return(KMIP_FALSE);
7931 }
7932 }
7933
7934 if(a->mac_signature_key_info != b->mac_signature_key_info)
7935 {
7936 if((a->mac_signature_key_info == NULL) || (b->mac_signature_key_info == NULL))
7937 {
7938 return(KMIP_FALSE);
7939 }
7940
7941 if(kmip_compare_mac_signature_key_information(a->mac_signature_key_info, b->mac_signature_key_info) == KMIP_FALSE)
7942 {
7943 return(KMIP_FALSE);
7944 }
7945 }
7946 }
7947
7948 return(KMIP_TRUE);
7949 }
7950
7951 int
7952 kmip_compare_key_block(const KeyBlock *a, const KeyBlock *b)
7953 {
7954 if(a != b)
7955 {
7956 if((a == NULL) || (b == NULL))
7957 {
7958 return(KMIP_FALSE);
7959 }
7960
7961 if(a->key_format_type != b->key_format_type)
7962 {
7963 return(KMIP_FALSE);
7964 }
7965
7966 if(a->key_compression_type != b->key_compression_type)
7967 {
7968 return(KMIP_FALSE);
7969 }
7970
7971 if(a->cryptographic_algorithm != b->cryptographic_algorithm)
7972 {
7973 return(KMIP_FALSE);
7974 }
7975
7976 if(a->cryptographic_length != b->cryptographic_length)
7977 {
7978 return(KMIP_FALSE);
7979 }
7980
7981 if(a->key_value_type != b->key_value_type)
7982 {
7983 return(KMIP_FALSE);
7984 }
7985
7986 if(a->key_value != b->key_value)
7987 {
7988 if((a->key_value == NULL) || (b->key_value == NULL))
7989 {
7990 return(KMIP_FALSE);
7991 }
7992
7993 if(a->key_value_type == KMIP_TYPE_BYTE_STRING)
7994 {
7995 if(kmip_compare_byte_string((ByteString *)a->key_value, (ByteString *)b->key_value) == KMIP_FALSE)
7996 {
7997 return(KMIP_FALSE);
7998 }
7999 }
8000 else
8001 {
8002 if(kmip_compare_key_value(a->key_format_type, (KeyValue *)a->key_value, (KeyValue *)b->key_value) == KMIP_FALSE)
8003 {
8004 return(KMIP_FALSE);
8005 }
8006 }
8007 }
8008
8009 if(a->key_wrapping_data != b->key_wrapping_data)
8010 {
8011 if((a->key_wrapping_data == NULL) || (b->key_wrapping_data == NULL))
8012 {
8013 return(KMIP_FALSE);
8014 }
8015
8016 if(kmip_compare_key_wrapping_data(a->key_wrapping_data, b->key_wrapping_data) == KMIP_FALSE)
8017 {
8018 return(KMIP_FALSE);
8019 }
8020 }
8021 }
8022
8023 return(KMIP_TRUE);
8024 }
8025
8026 int
8027 kmip_compare_symmetric_key(const SymmetricKey *a, const SymmetricKey *b)
8028 {
8029 if(a != b)
8030 {
8031 if((a == NULL) || (b == NULL))
8032 {
8033 return(KMIP_FALSE);
8034 }
8035
8036 if(a->key_block != b->key_block)
8037 {
8038 if((a->key_block == NULL) || (b->key_block == NULL))
8039 {
8040 return(KMIP_FALSE);
8041 }
8042
8043 if(kmip_compare_key_block(a->key_block, b->key_block) == KMIP_FALSE)
8044 {
8045 return(KMIP_FALSE);
8046 }
8047 }
8048 }
8049
8050 return(KMIP_TRUE);
8051 }
8052
8053 int
8054 kmip_compare_public_key(const PublicKey *a, const PublicKey *b)
8055 {
8056 if(a != b)
8057 {
8058 if((a == NULL) || (b == NULL))
8059 {
8060 return(KMIP_FALSE);
8061 }
8062
8063 if(a->key_block != b->key_block)
8064 {
8065 if((a->key_block == NULL) || (b->key_block == NULL))
8066 {
8067 return(KMIP_FALSE);
8068 }
8069
8070 if(kmip_compare_key_block(a->key_block, b->key_block) == KMIP_FALSE)
8071 {
8072 return(KMIP_FALSE);
8073 }
8074 }
8075 }
8076
8077 return(KMIP_TRUE);
8078 }
8079
8080 int
8081 kmip_compare_private_key(const PrivateKey *a, const PrivateKey *b)
8082 {
8083 if(a != b)
8084 {
8085 if((a == NULL) || (b == NULL))
8086 {
8087 return(KMIP_FALSE);
8088 }
8089
8090 if(a->key_block != b->key_block)
8091 {
8092 if((a->key_block == NULL) || (b->key_block == NULL))
8093 {
8094 return(KMIP_FALSE);
8095 }
8096
8097 if(kmip_compare_key_block(a->key_block, b->key_block) == KMIP_FALSE)
8098 {
8099 return(KMIP_FALSE);
8100 }
8101 }
8102 }
8103
8104 return(KMIP_TRUE);
8105 }
8106
8107 int
8108 kmip_compare_key_wrapping_specification(const KeyWrappingSpecification *a, const KeyWrappingSpecification *b)
8109 {
8110 if(a != b)
8111 {
8112 if((a == NULL) || (b == NULL))
8113 {
8114 return(KMIP_FALSE);
8115 }
8116
8117 if(a->wrapping_method != b->wrapping_method)
8118 {
8119 return(KMIP_FALSE);
8120 }
8121
8122 if(a->encoding_option != b->encoding_option)
8123 {
8124 return(KMIP_FALSE);
8125 }
8126
8127 if(a->attribute_name_count != b->attribute_name_count)
8128 {
8129 return(KMIP_FALSE);
8130 }
8131
8132 if(a->encryption_key_info != b->encryption_key_info)
8133 {
8134 if((a->encryption_key_info == NULL) || (b->encryption_key_info == NULL))
8135 {
8136 return(KMIP_FALSE);
8137 }
8138
8139 if(kmip_compare_encryption_key_information(a->encryption_key_info, b->encryption_key_info) == KMIP_FALSE)
8140 {
8141 return(KMIP_FALSE);
8142 }
8143 }
8144
8145 if(a->mac_signature_key_info != b->mac_signature_key_info)
8146 {
8147 if((a->mac_signature_key_info == NULL) || (b->mac_signature_key_info == NULL))
8148 {
8149 return(KMIP_FALSE);
8150 }
8151
8152 if(kmip_compare_mac_signature_key_information(a->mac_signature_key_info, b->mac_signature_key_info) == KMIP_FALSE)
8153 {
8154 return(KMIP_FALSE);
8155 }
8156 }
8157
8158 if(a->attribute_names != b->attribute_names)
8159 {
8160 if((a->attribute_names == NULL) || (b->attribute_names == NULL))
8161 {
8162 return(KMIP_FALSE);
8163 }
8164
8165 for(size_t i = 0; i < a->attribute_name_count; i++)
8166 {
8167 if(kmip_compare_text_string(&a->attribute_names[i], &b->attribute_names[i]) == KMIP_FALSE)
8168 {
8169 return(KMIP_FALSE);
8170 }
8171 }
8172 }
8173 }
8174
8175 return(KMIP_TRUE);
8176 }
8177
8178 int
8179 kmip_compare_create_request_payload(const CreateRequestPayload *a, const CreateRequestPayload *b)
8180 {
8181 if(a != b)
8182 {
8183 if((a == NULL) || (b == NULL))
8184 {
8185 return(KMIP_FALSE);
8186 }
8187
8188 if(a->object_type != b->object_type)
8189 {
8190 return(KMIP_FALSE);
8191 }
8192
8193 if(a->template_attribute != b->template_attribute)
8194 {
8195 if((a->template_attribute == NULL) || (b->template_attribute == NULL))
8196 {
8197 return(KMIP_FALSE);
8198 }
8199
8200 if(kmip_compare_template_attribute(a->template_attribute, b->template_attribute) == KMIP_FALSE)
8201 {
8202 return(KMIP_FALSE);
8203 }
8204 }
8205
8206 if(a->attributes != b->attributes)
8207 {
8208 if((a->attributes == NULL) || (b->attributes == NULL))
8209 {
8210 return(KMIP_FALSE);
8211 }
8212
8213 if(kmip_compare_attributes(a->attributes, b->attributes) == KMIP_FALSE)
8214 {
8215 return(KMIP_FALSE);
8216 }
8217 }
8218
8219 if(a->protection_storage_masks != b->protection_storage_masks)
8220 {
8221 if((a->protection_storage_masks == NULL) || (b->protection_storage_masks == NULL))
8222 {
8223 return(KMIP_FALSE);
8224 }
8225
8226 if(kmip_compare_protection_storage_masks(a->protection_storage_masks, b->protection_storage_masks) == KMIP_FALSE)
8227 {
8228 return(KMIP_FALSE);
8229 }
8230 }
8231 }
8232
8233 return(KMIP_TRUE);
8234 }
8235
8236 int
8237 kmip_compare_create_response_payload(const CreateResponsePayload *a, const CreateResponsePayload *b)
8238 {
8239 if(a != b)
8240 {
8241 if((a == NULL) || (b == NULL))
8242 {
8243 return(KMIP_FALSE);
8244 }
8245
8246 if(a->object_type != b->object_type)
8247 {
8248 return(KMIP_FALSE);
8249 }
8250
8251 if(a->unique_identifier != b->unique_identifier)
8252 {
8253 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
8254 {
8255 return(KMIP_FALSE);
8256 }
8257
8258 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
8259 {
8260 return(KMIP_FALSE);
8261 }
8262 }
8263
8264 if(a->template_attribute != b->template_attribute)
8265 {
8266 if((a->template_attribute == NULL) || (b->template_attribute == NULL))
8267 {
8268 return(KMIP_FALSE);
8269 }
8270
8271 if(kmip_compare_template_attribute(a->template_attribute, b->template_attribute) == KMIP_FALSE)
8272 {
8273 return(KMIP_FALSE);
8274 }
8275 }
8276 }
8277
8278 return(KMIP_TRUE);
8279 }
8280
8281 int
8282 kmip_compare_register_request_payload(const RegisterRequestPayload *a, const RegisterRequestPayload *b)
8283 {
8284 if(a != b)
8285 {
8286 if((a == NULL) || (b == NULL))
8287 {
8288 return(KMIP_FALSE);
8289 }
8290
8291 if(a->object_type != b->object_type)
8292 {
8293 return(KMIP_FALSE);
8294 }
8295
8296 if(a->template_attribute != b->template_attribute)
8297 {
8298 if((a->template_attribute == NULL) || (b->template_attribute == NULL))
8299 {
8300 return(KMIP_FALSE);
8301 }
8302
8303 if(kmip_compare_template_attribute(a->template_attribute, b->template_attribute) == KMIP_FALSE)
8304 {
8305 return(KMIP_FALSE);
8306 }
8307 }
8308
8309 if(a->attributes != b->attributes)
8310 {
8311 if((a->attributes == NULL) || (b->attributes == NULL))
8312 {
8313 return(KMIP_FALSE);
8314 }
8315
8316 if(kmip_compare_attributes(a->attributes, b->attributes) == KMIP_FALSE)
8317 {
8318 return(KMIP_FALSE);
8319 }
8320 }
8321
8322 if(a->protection_storage_masks != b->protection_storage_masks)
8323 {
8324 if((a->protection_storage_masks == NULL) || (b->protection_storage_masks == NULL))
8325 {
8326 return(KMIP_FALSE);
8327 }
8328
8329 if(kmip_compare_protection_storage_masks(a->protection_storage_masks, b->protection_storage_masks) == KMIP_FALSE)
8330 {
8331 return(KMIP_FALSE);
8332 }
8333 }
8334
8335 return kmip_compare_symmetric_key(&a->object, &b->object);
8336 }
8337
8338 return(KMIP_TRUE);
8339 }
8340
8341 int
8342 kmip_compare_register_response_payload(const RegisterResponsePayload *a, const RegisterResponsePayload *b)
8343 {
8344 if(a != b)
8345 {
8346 if((a == NULL) || (b == NULL))
8347 {
8348 return(KMIP_FALSE);
8349 }
8350
8351 if(a->unique_identifier != b->unique_identifier)
8352 {
8353 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
8354 {
8355 return(KMIP_FALSE);
8356 }
8357
8358 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
8359 {
8360 return(KMIP_FALSE);
8361 }
8362 }
8363
8364 if(a->template_attribute != b->template_attribute)
8365 {
8366 if((a->template_attribute == NULL) || (b->template_attribute == NULL))
8367 {
8368 return(KMIP_FALSE);
8369 }
8370
8371 if(kmip_compare_template_attribute(a->template_attribute, b->template_attribute) == KMIP_FALSE)
8372 {
8373 return(KMIP_FALSE);
8374 }
8375 }
8376 }
8377
8378 return(KMIP_TRUE);
8379 }
8380
8381 int
8382 kmip_compare_get_request_payload(const GetRequestPayload *a, const GetRequestPayload *b)
8383 {
8384 if(a != b)
8385 {
8386 if((a == NULL) || (b == NULL))
8387 {
8388 return(KMIP_FALSE);
8389 }
8390
8391 if(a->key_format_type != b->key_format_type)
8392 {
8393 return(KMIP_FALSE);
8394 }
8395
8396 if(a->key_compression_type != b->key_compression_type)
8397 {
8398 return(KMIP_FALSE);
8399 }
8400
8401 if(a->key_wrap_type != b->key_wrap_type)
8402 {
8403 return(KMIP_FALSE);
8404 }
8405
8406 if(a->unique_identifier != b->unique_identifier)
8407 {
8408 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
8409 {
8410 return(KMIP_FALSE);
8411 }
8412
8413 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
8414 {
8415 return(KMIP_FALSE);
8416 }
8417 }
8418
8419 if(a->key_wrapping_spec != b->key_wrapping_spec)
8420 {
8421 if((a->key_wrapping_spec == NULL) || (b->key_wrapping_spec == NULL))
8422 {
8423 return(KMIP_FALSE);
8424 }
8425
8426 if(kmip_compare_key_wrapping_specification(a->key_wrapping_spec, b->key_wrapping_spec) == KMIP_FALSE)
8427 {
8428 return(KMIP_FALSE);
8429 }
8430 }
8431 }
8432
8433 return(KMIP_TRUE);
8434 }
8435
8436 int
8437 kmip_compare_get_response_payload(const GetResponsePayload *a, const GetResponsePayload *b)
8438 {
8439 if(a != b)
8440 {
8441 if((a == NULL) || (b == NULL))
8442 {
8443 return(KMIP_FALSE);
8444 }
8445
8446 if(a->object_type != b->object_type)
8447 {
8448 return(KMIP_FALSE);
8449 }
8450
8451 if(a->unique_identifier != b->unique_identifier)
8452 {
8453 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
8454 {
8455 return(KMIP_FALSE);
8456 }
8457
8458 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
8459 {
8460 return(KMIP_FALSE);
8461 }
8462 }
8463
8464 if(a->object != b->object)
8465 {
8466 switch(a->object_type)
8467 {
8468 case KMIP_OBJTYPE_SYMMETRIC_KEY:
8469 if(kmip_compare_symmetric_key((SymmetricKey *)a->object, (SymmetricKey *)b->object) == KMIP_FALSE)
8470 {
8471 return(KMIP_FALSE);
8472 }
8473 break;
8474
8475 case KMIP_OBJTYPE_PUBLIC_KEY:
8476 if(kmip_compare_public_key((PublicKey *)a->object, (PublicKey *)b->object) == KMIP_FALSE)
8477 {
8478 return(KMIP_FALSE);
8479 }
8480 break;
8481
8482 case KMIP_OBJTYPE_PRIVATE_KEY:
8483 if(kmip_compare_private_key((PrivateKey *)a->object, (PrivateKey *)b->object) == KMIP_FALSE)
8484 {
8485 return(KMIP_FALSE);
8486 }
8487 break;
8488
8489 default:
8490 /* NOTE (ph) Unsupported types cannot be compared. */
8491 return(KMIP_FALSE);
8492 break;
8493 };
8494 }
8495 }
8496
8497 return(KMIP_TRUE);
8498 }
8499
8500 int
8501 kmip_compare_get_attribute_request_payload(const GetAttributeRequestPayload *a, const GetAttributeRequestPayload *b)
8502 {
8503 if(a != b)
8504 {
8505 if((a == NULL) || (b == NULL))
8506 {
8507 return(KMIP_FALSE);
8508 }
8509
8510 if(a->unique_identifier != b->unique_identifier)
8511 {
8512 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
8513 {
8514 return(KMIP_FALSE);
8515 }
8516
8517 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
8518 {
8519 return(KMIP_FALSE);
8520 }
8521 }
8522
8523 if(a->attribute_name != b->attribute_name)
8524 {
8525 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
8526 {
8527 return(KMIP_FALSE);
8528 }
8529
8530 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
8531 {
8532 return(KMIP_FALSE);
8533 }
8534 }
8535
8536 }
8537
8538 return(KMIP_TRUE);
8539 }
8540
8541 int
8542 kmip_compare_get_attribute_response_payload(const GetAttributeResponsePayload *a, const GetAttributeResponsePayload *b)
8543 {
8544 if(a != b)
8545 {
8546 if((a == NULL) || (b == NULL))
8547 {
8548 return(KMIP_FALSE);
8549 }
8550
8551 if(a->unique_identifier != b->unique_identifier)
8552 {
8553 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
8554 {
8555 return(KMIP_FALSE);
8556 }
8557
8558 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
8559 {
8560 return(KMIP_FALSE);
8561 }
8562 }
8563
8564 // TODO: attribute
8565 }
8566
8567 return(KMIP_TRUE);
8568 }
8569
8570 int
8571 kmip_compare_destroy_request_payload(const DestroyRequestPayload *a, const DestroyRequestPayload *b)
8572 {
8573 if(a != b)
8574 {
8575 if((a == NULL) || (b == NULL))
8576 {
8577 return(KMIP_FALSE);
8578 }
8579
8580 if(a->unique_identifier != b->unique_identifier)
8581 {
8582 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
8583 {
8584 return(KMIP_FALSE);
8585 }
8586
8587 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
8588 {
8589 return(KMIP_FALSE);
8590 }
8591 }
8592 }
8593
8594 return(KMIP_TRUE);
8595 }
8596
8597 int
8598 kmip_compare_destroy_response_payload(const DestroyResponsePayload *a, const DestroyResponsePayload *b)
8599 {
8600 if(a != b)
8601 {
8602 if((a == NULL) || (b == NULL))
8603 {
8604 return(KMIP_FALSE);
8605 }
8606
8607 if(a->unique_identifier != b->unique_identifier)
8608 {
8609 if((a->unique_identifier == NULL) || (b->unique_identifier == NULL))
8610 {
8611 return(KMIP_FALSE);
8612 }
8613
8614 if(kmip_compare_text_string(a->unique_identifier, b->unique_identifier) == KMIP_FALSE)
8615 {
8616 return(KMIP_FALSE);
8617 }
8618 }
8619 }
8620
8621 return(KMIP_TRUE);
8622 }
8623
8624 int
8625 kmip_compare_request_batch_item(const RequestBatchItem *a, const RequestBatchItem *b)
8626 {
8627 if(a != b)
8628 {
8629 if((a == NULL) || (b == NULL))
8630 {
8631 return(KMIP_FALSE);
8632 }
8633
8634 if(a->operation != b->operation)
8635 {
8636 return(KMIP_FALSE);
8637 }
8638
8639 if(a->ephemeral != b->ephemeral)
8640 {
8641 return(KMIP_FALSE);
8642 }
8643
8644 if(a->unique_batch_item_id != b->unique_batch_item_id)
8645 {
8646 if((a->unique_batch_item_id == NULL) || (b->unique_batch_item_id == NULL))
8647 {
8648 return(KMIP_FALSE);
8649 }
8650
8651 if(kmip_compare_byte_string(a->unique_batch_item_id, b->unique_batch_item_id) == KMIP_FALSE)
8652 {
8653 return(KMIP_FALSE);
8654 }
8655 }
8656
8657 if(a->request_payload != b->request_payload)
8658 {
8659 if((a->request_payload == NULL) || (b->request_payload == NULL))
8660 {
8661 return(KMIP_FALSE);
8662 }
8663
8664 switch(a->operation)
8665 {
8666 case KMIP_OP_CREATE:
8667 if(kmip_compare_create_request_payload((CreateRequestPayload *)a->request_payload, (CreateRequestPayload *)b->request_payload) == KMIP_FALSE)
8668 {
8669 return(KMIP_FALSE);
8670 }
8671 break;
8672
8673 case KMIP_OP_REGISTER:
8674 if(kmip_compare_register_request_payload((RegisterRequestPayload *)a->request_payload, (RegisterRequestPayload *)b->request_payload) == KMIP_FALSE)
8675 {
8676 return(KMIP_FALSE);
8677 }
8678 break;
8679
8680 case KMIP_OP_GET:
8681 if(kmip_compare_get_request_payload((GetRequestPayload *)a->request_payload, (GetRequestPayload *)b->request_payload) == KMIP_FALSE)
8682 {
8683 return(KMIP_FALSE);
8684 }
8685 break;
8686
8687 case KMIP_OP_GET_ATTRIBUTES:
8688 if(kmip_compare_get_attribute_request_payload((GetAttributeRequestPayload *)a->request_payload, (GetAttributeRequestPayload *)b->request_payload) == KMIP_FALSE)
8689 {
8690 return(KMIP_FALSE);
8691 }
8692 break;
8693
8694 case KMIP_OP_DESTROY:
8695 if(kmip_compare_destroy_request_payload((DestroyRequestPayload *)a->request_payload, (DestroyRequestPayload *)b->request_payload) == KMIP_FALSE)
8696 {
8697 return(KMIP_FALSE);
8698 }
8699 break;
8700
8701 case KMIP_OP_QUERY:
8702 if(kmip_compare_query_request_payload((QueryRequestPayload *)a->request_payload, (QueryRequestPayload *)b->request_payload) == KMIP_FALSE)
8703 {
8704 return(KMIP_FALSE);
8705 }
8706 break;
8707
8708 case KMIP_OP_LOCATE:
8709 if(kmip_compare_locate_request_payload((LocateRequestPayload *)a->request_payload, (LocateRequestPayload *)b->request_payload) == KMIP_FALSE)
8710 {
8711 return(KMIP_FALSE);
8712 }
8713 break;
8714
8715 default:
8716 /* NOTE (ph) Unsupported payloads cannot be compared. */
8717 return(KMIP_FALSE);
8718 break;
8719 };
8720 }
8721 }
8722
8723 return(KMIP_TRUE);
8724 }
8725
8726 int
8727 kmip_compare_response_batch_item(const ResponseBatchItem *a, const ResponseBatchItem *b)
8728 {
8729 if(a != b)
8730 {
8731 if((a == NULL) || (b == NULL))
8732 {
8733 return(KMIP_FALSE);
8734 }
8735
8736 if(a->operation != b->operation)
8737 {
8738 return(KMIP_FALSE);
8739 }
8740
8741 if(a->result_status != b->result_status)
8742 {
8743 return(KMIP_FALSE);
8744 }
8745
8746 if(a->result_reason != b->result_reason)
8747 {
8748 return(KMIP_FALSE);
8749 }
8750
8751 if(a->unique_batch_item_id != b->unique_batch_item_id)
8752 {
8753 if((a->unique_batch_item_id == NULL) || (b->unique_batch_item_id == NULL))
8754 {
8755 return(KMIP_FALSE);
8756 }
8757
8758 if(kmip_compare_byte_string(a->unique_batch_item_id, b->unique_batch_item_id) == KMIP_FALSE)
8759 {
8760 return(KMIP_FALSE);
8761 }
8762 }
8763
8764 if(a->result_message != b->result_message)
8765 {
8766 if((a->result_message == NULL) || (b->result_message == NULL))
8767 {
8768 return(KMIP_FALSE);
8769 }
8770
8771 if(kmip_compare_text_string(a->result_message, b->result_message) == KMIP_FALSE)
8772 {
8773 return(KMIP_FALSE);
8774 }
8775 }
8776
8777 if(a->asynchronous_correlation_value != b->asynchronous_correlation_value)
8778 {
8779 if((a->asynchronous_correlation_value == NULL) || (b->asynchronous_correlation_value == NULL))
8780 {
8781 return(KMIP_FALSE);
8782 }
8783
8784 if(kmip_compare_byte_string(a->asynchronous_correlation_value, b->asynchronous_correlation_value) == KMIP_FALSE)
8785 {
8786 return(KMIP_FALSE);
8787 }
8788 }
8789
8790 if(a->response_payload != b->response_payload)
8791 {
8792 if((a->response_payload == NULL) || (b->response_payload == NULL))
8793 {
8794 return(KMIP_FALSE);
8795 }
8796
8797 switch(a->operation)
8798 {
8799 case KMIP_OP_CREATE:
8800 if(kmip_compare_create_response_payload((CreateResponsePayload *)a->response_payload, (CreateResponsePayload *)b->response_payload) == KMIP_FALSE)
8801 {
8802 return(KMIP_FALSE);
8803 }
8804 break;
8805
8806 case KMIP_OP_GET:
8807 if(kmip_compare_get_response_payload((GetResponsePayload *)a->response_payload, (GetResponsePayload *)b->response_payload) == KMIP_FALSE)
8808 {
8809 return(KMIP_FALSE);
8810 }
8811 break;
8812
8813 case KMIP_OP_GET_ATTRIBUTES:
8814 if(kmip_compare_get_attribute_response_payload((GetAttributeResponsePayload *)a->response_payload, (GetAttributeResponsePayload *)b->response_payload) == KMIP_FALSE)
8815 {
8816 return(KMIP_FALSE);
8817 }
8818 break;
8819
8820 case KMIP_OP_DESTROY:
8821 if(kmip_compare_destroy_response_payload((DestroyResponsePayload *)a->response_payload, (DestroyResponsePayload *)b->response_payload) == KMIP_FALSE)
8822 {
8823 return(KMIP_FALSE);
8824 }
8825 break;
8826
8827 case KMIP_OP_QUERY:
8828 if(kmip_compare_query_response_payload((QueryResponsePayload *)a->response_payload, (QueryResponsePayload *)b->response_payload) == KMIP_FALSE)
8829 {
8830 return(KMIP_FALSE);
8831 }
8832 break;
8833
8834 case KMIP_OP_LOCATE:
8835 if(kmip_compare_locate_response_payload((LocateResponsePayload *)a->response_payload, (LocateResponsePayload *)b->response_payload) == KMIP_FALSE)
8836 {
8837 return(KMIP_FALSE);
8838 }
8839 break;
8840
8841 default:
8842 /* NOTE (ph) Unsupported payloads cannot be compared. */
8843 return(KMIP_FALSE);
8844 break;
8845 };
8846 }
8847 }
8848
8849 return(KMIP_TRUE);
8850 }
8851
8852 int
8853 kmip_compare_nonce(const Nonce *a, const Nonce *b)
8854 {
8855 if(a != b)
8856 {
8857 if((a == NULL) || (b == NULL))
8858 {
8859 return(KMIP_FALSE);
8860 }
8861
8862 if(a->nonce_id != b->nonce_id)
8863 {
8864 if((a->nonce_id == NULL) || (b->nonce_id == NULL))
8865 {
8866 return(KMIP_FALSE);
8867 }
8868
8869 if(kmip_compare_byte_string(a->nonce_id, b->nonce_id) == KMIP_FALSE)
8870 {
8871 return(KMIP_FALSE);
8872 }
8873 }
8874
8875 if(a->nonce_value != b->nonce_value)
8876 {
8877 if((a->nonce_value == NULL) || (b->nonce_value == NULL))
8878 {
8879 return(KMIP_FALSE);
8880 }
8881
8882 if(kmip_compare_byte_string(a->nonce_value, b->nonce_value) == KMIP_FALSE)
8883 {
8884 return(KMIP_FALSE);
8885 }
8886 }
8887 }
8888
8889 return(KMIP_TRUE);
8890 }
8891
8892 int
8893 kmip_compare_username_password_credential(const UsernamePasswordCredential *a, const UsernamePasswordCredential *b)
8894 {
8895 if(a != b)
8896 {
8897 if((a == NULL) || (b == NULL))
8898 {
8899 return(KMIP_FALSE);
8900 }
8901
8902 if(a->username != b->username)
8903 {
8904 if((a->username == NULL) || (b->username == NULL))
8905 {
8906 return(KMIP_FALSE);
8907 }
8908
8909 if(kmip_compare_text_string(a->username, b->username) == KMIP_FALSE)
8910 {
8911 return(KMIP_FALSE);
8912 }
8913 }
8914
8915 if(a->password != b->password)
8916 {
8917 if((a->password == NULL) || (b->password == NULL))
8918 {
8919 return(KMIP_FALSE);
8920 }
8921
8922 if(kmip_compare_text_string(a->password, b->password) == KMIP_FALSE)
8923 {
8924 return(KMIP_FALSE);
8925 }
8926 }
8927 }
8928
8929 return(KMIP_TRUE);
8930 }
8931
8932 int
8933 kmip_compare_device_credential(const DeviceCredential *a, const DeviceCredential *b)
8934 {
8935 if(a != b)
8936 {
8937 if((a == NULL) || (b == NULL))
8938 {
8939 return(KMIP_FALSE);
8940 }
8941
8942 if(a->device_serial_number != b->device_serial_number)
8943 {
8944 if((a->device_serial_number == NULL) || (b->device_serial_number == NULL))
8945 {
8946 return(KMIP_FALSE);
8947 }
8948
8949 if(kmip_compare_text_string(a->device_serial_number, b->device_serial_number) == KMIP_FALSE)
8950 {
8951 return(KMIP_FALSE);
8952 }
8953 }
8954
8955 if(a->password != b->password)
8956 {
8957 if((a->password == NULL) || (b->password == NULL))
8958 {
8959 return(KMIP_FALSE);
8960 }
8961
8962 if(kmip_compare_text_string(a->password, b->password) == KMIP_FALSE)
8963 {
8964 return(KMIP_FALSE);
8965 }
8966 }
8967
8968 if(a->device_identifier != b->device_identifier)
8969 {
8970 if((a->device_identifier == NULL) || (b->device_identifier == NULL))
8971 {
8972 return(KMIP_FALSE);
8973 }
8974
8975 if(kmip_compare_text_string(a->device_identifier, b->device_identifier) == KMIP_FALSE)
8976 {
8977 return(KMIP_FALSE);
8978 }
8979 }
8980
8981 if(a->network_identifier != b->network_identifier)
8982 {
8983 if((a->network_identifier == NULL) || (b->network_identifier == NULL))
8984 {
8985 return(KMIP_FALSE);
8986 }
8987
8988 if(kmip_compare_text_string(a->network_identifier, b->network_identifier) == KMIP_FALSE)
8989 {
8990 return(KMIP_FALSE);
8991 }
8992 }
8993
8994 if(a->machine_identifier != b->machine_identifier)
8995 {
8996 if((a->machine_identifier == NULL) || (b->machine_identifier == NULL))
8997 {
8998 return(KMIP_FALSE);
8999 }
9000
9001 if(kmip_compare_text_string(a->machine_identifier, b->machine_identifier) == KMIP_FALSE)
9002 {
9003 return(KMIP_FALSE);
9004 }
9005 }
9006
9007 if(a->media_identifier != b->media_identifier)
9008 {
9009 if((a->media_identifier == NULL) || (b->media_identifier == NULL))
9010 {
9011 return(KMIP_FALSE);
9012 }
9013
9014 if(kmip_compare_text_string(a->media_identifier, b->media_identifier) == KMIP_FALSE)
9015 {
9016 return(KMIP_FALSE);
9017 }
9018 }
9019 }
9020
9021 return(KMIP_TRUE);
9022 }
9023
9024 int
9025 kmip_compare_attestation_credential(const AttestationCredential *a, const AttestationCredential *b)
9026 {
9027 if(a != b)
9028 {
9029 if((a == NULL) || (b == NULL))
9030 {
9031 return(KMIP_FALSE);
9032 }
9033
9034 if(a->attestation_type != b->attestation_type)
9035 {
9036 return(KMIP_FALSE);
9037 }
9038
9039 if(a->nonce != b->nonce)
9040 {
9041 if((a->nonce == NULL) || (b->nonce == NULL))
9042 {
9043 return(KMIP_FALSE);
9044 }
9045
9046 if(kmip_compare_nonce(a->nonce, b->nonce) == KMIP_FALSE)
9047 {
9048 return(KMIP_FALSE);
9049 }
9050 }
9051
9052 if(a->attestation_measurement != b->attestation_measurement)
9053 {
9054 if((a->attestation_measurement == NULL) || (b->attestation_measurement == NULL))
9055 {
9056 return(KMIP_FALSE);
9057 }
9058
9059 if(kmip_compare_byte_string(a->attestation_measurement, b->attestation_measurement) == KMIP_FALSE)
9060 {
9061 return(KMIP_FALSE);
9062 }
9063 }
9064
9065 if(a->attestation_assertion != b->attestation_assertion)
9066 {
9067 if((a->attestation_assertion == NULL) || (b->attestation_assertion == NULL))
9068 {
9069 return(KMIP_FALSE);
9070 }
9071
9072 if(kmip_compare_byte_string(a->attestation_assertion, b->attestation_assertion) == KMIP_FALSE)
9073 {
9074 return(KMIP_FALSE);
9075 }
9076 }
9077 }
9078
9079 return(KMIP_TRUE);
9080 }
9081
9082 int
9083 kmip_compare_credential_value(enum credential_type type, void **a, void **b)
9084 {
9085 if(a != b)
9086 {
9087 if((a == NULL) || (b == NULL))
9088 {
9089 return(KMIP_FALSE);
9090 }
9091
9092 if(*a != *b)
9093 {
9094 if((*a == NULL) || (*b == NULL))
9095 {
9096 return(KMIP_FALSE);
9097 }
9098
9099 switch(type)
9100 {
9101 case KMIP_CRED_USERNAME_AND_PASSWORD:
9102 if(kmip_compare_username_password_credential(*a, *b) == KMIP_FALSE)
9103 {
9104 return(KMIP_FALSE);
9105 }
9106 break;
9107
9108 case KMIP_CRED_DEVICE:
9109 if(kmip_compare_device_credential(*a, *b) == KMIP_FALSE)
9110 {
9111 return(KMIP_FALSE);
9112 }
9113 break;
9114
9115 case KMIP_CRED_ATTESTATION:
9116 if(kmip_compare_attestation_credential(*a, *b) == KMIP_FALSE)
9117 {
9118 return(KMIP_FALSE);
9119 }
9120 break;
9121
9122 default:
9123 /* NOTE (ph) Unsupported types cannot be compared. */
9124 return(KMIP_FALSE);
9125 break;
9126 };
9127 }
9128 }
9129
9130 return(KMIP_TRUE);
9131 }
9132
9133 int
9134 kmip_compare_credential(const Credential *a, const Credential *b)
9135 {
9136 if(a != b)
9137 {
9138 if((a == NULL) || (b == NULL))
9139 {
9140 return(KMIP_FALSE);
9141 }
9142
9143 if(a->credential_type != b->credential_type)
9144 {
9145 return(KMIP_FALSE);
9146 }
9147
9148 if(a->credential_value != b->credential_value)
9149 {
9150 if((a->credential_value == NULL) || (b->credential_value == NULL))
9151 {
9152 return(KMIP_FALSE);
9153 }
9154
9155 if(kmip_compare_credential_value(a->credential_type, (void**)&a->credential_value, (void**)&b->credential_value) == KMIP_FALSE)
9156 {
9157 return(KMIP_FALSE);
9158 }
9159 }
9160 }
9161
9162 return(KMIP_TRUE);
9163 }
9164
9165 int
9166 kmip_compare_authentication(const Authentication *a, const Authentication *b)
9167 {
9168 if(a != b)
9169 {
9170 if((a == NULL) || (b == NULL))
9171 {
9172 return(KMIP_FALSE);
9173 }
9174
9175 if(a->credential != b->credential)
9176 {
9177 if((a->credential == NULL) || (b->credential == NULL))
9178 {
9179 return(KMIP_FALSE);
9180 }
9181
9182 if(kmip_compare_credential(a->credential, b->credential) == KMIP_FALSE)
9183 {
9184 return(KMIP_FALSE);
9185 }
9186 }
9187 }
9188
9189 return(KMIP_TRUE);
9190 }
9191
9192 int
9193 kmip_compare_request_header(const RequestHeader *a, const RequestHeader *b)
9194 {
9195 if(a != b)
9196 {
9197 if((a == NULL) || (b == NULL))
9198 {
9199 return(KMIP_FALSE);
9200 }
9201
9202 if(a->maximum_response_size != b->maximum_response_size)
9203 {
9204 return(KMIP_FALSE);
9205 }
9206
9207 if(a->asynchronous_indicator != b->asynchronous_indicator)
9208 {
9209 return(KMIP_FALSE);
9210 }
9211
9212 if(a->batch_error_continuation_option != b->batch_error_continuation_option)
9213 {
9214 return(KMIP_FALSE);
9215 }
9216
9217 if(a->batch_order_option != b->batch_order_option)
9218 {
9219 return(KMIP_FALSE);
9220 }
9221
9222 if(a->time_stamp != b->time_stamp)
9223 {
9224 return(KMIP_FALSE);
9225 }
9226
9227 if(a->batch_count != b->batch_count)
9228 {
9229 return(KMIP_FALSE);
9230 }
9231
9232 if(a->attestation_capable_indicator != b->attestation_capable_indicator)
9233 {
9234 return(KMIP_FALSE);
9235 }
9236
9237 if(a->attestation_type_count != b->attestation_type_count)
9238 {
9239 return(KMIP_FALSE);
9240 }
9241
9242 if(a->protocol_version != b->protocol_version)
9243 {
9244 if((a->protocol_version == NULL) || (b->protocol_version == NULL))
9245 {
9246 return(KMIP_FALSE);
9247 }
9248
9249 if(kmip_compare_protocol_version(a->protocol_version, b->protocol_version) == KMIP_FALSE)
9250 {
9251 return(KMIP_FALSE);
9252 }
9253 }
9254
9255 if(a->authentication != b->authentication)
9256 {
9257 if((a->authentication == NULL) || (b->authentication == NULL))
9258 {
9259 return(KMIP_FALSE);
9260 }
9261
9262 if(kmip_compare_authentication(a->authentication, b->authentication) == KMIP_FALSE)
9263 {
9264 return(KMIP_FALSE);
9265 }
9266 }
9267
9268 if(a->attestation_types != b->attestation_types)
9269 {
9270 if((a->attestation_types == NULL) || (b->attestation_types == NULL))
9271 {
9272 return(KMIP_FALSE);
9273 }
9274
9275 for(size_t i = 0; i < a->attestation_type_count; i++)
9276 {
9277 if(a->attestation_types[i] != b->attestation_types[i])
9278 {
9279 return(KMIP_FALSE);
9280 }
9281 }
9282 }
9283
9284 if(a->client_correlation_value != b->client_correlation_value)
9285 {
9286 if((a->client_correlation_value == NULL) || (b->client_correlation_value == NULL))
9287 {
9288 return(KMIP_FALSE);
9289 }
9290
9291 if(kmip_compare_text_string(a->client_correlation_value, b->client_correlation_value) == KMIP_FALSE)
9292 {
9293 return(KMIP_FALSE);
9294 }
9295 }
9296
9297 if(a->server_correlation_value != b->server_correlation_value)
9298 {
9299 if((a->server_correlation_value == NULL) || (b->server_correlation_value == NULL))
9300 {
9301 return(KMIP_FALSE);
9302 }
9303
9304 if(kmip_compare_text_string(a->server_correlation_value, b->server_correlation_value) == KMIP_FALSE)
9305 {
9306 return(KMIP_FALSE);
9307 }
9308 }
9309 }
9310
9311 return(KMIP_TRUE);
9312 }
9313
9314 int
9315 kmip_compare_response_header(const ResponseHeader *a, const ResponseHeader *b)
9316 {
9317 if(a != b)
9318 {
9319 if((a == NULL) || (b == NULL))
9320 {
9321 return(KMIP_FALSE);
9322 }
9323
9324 if(a->time_stamp != b->time_stamp)
9325 {
9326 return(KMIP_FALSE);
9327 }
9328
9329 if(a->batch_count != b->batch_count)
9330 {
9331 return(KMIP_FALSE);
9332 }
9333
9334 if(a->attestation_type_count != b->attestation_type_count)
9335 {
9336 return(KMIP_FALSE);
9337 }
9338
9339 if(a->protocol_version != b->protocol_version)
9340 {
9341 if((a->protocol_version == NULL) || (b->protocol_version == NULL))
9342 {
9343 return(KMIP_FALSE);
9344 }
9345
9346 if(kmip_compare_protocol_version(a->protocol_version, b->protocol_version) == KMIP_FALSE)
9347 {
9348 return(KMIP_FALSE);
9349 }
9350 }
9351
9352 if(a->nonce != b->nonce)
9353 {
9354 if((a->nonce == NULL) || (b->nonce == NULL))
9355 {
9356 return(KMIP_FALSE);
9357 }
9358
9359 if(kmip_compare_nonce(a->nonce, b->nonce) == KMIP_FALSE)
9360 {
9361 return(KMIP_FALSE);
9362 }
9363 }
9364
9365 if(a->server_hashed_password != b->server_hashed_password)
9366 {
9367 if((a->server_hashed_password == NULL) || (b->server_hashed_password == NULL))
9368 return(KMIP_FALSE);
9369
9370 if(kmip_compare_byte_string(a->server_hashed_password, b->server_hashed_password) == KMIP_FALSE)
9371 return(KMIP_FALSE);
9372 }
9373
9374 if(a->attestation_types != b->attestation_types)
9375 {
9376 if((a->attestation_types == NULL) || (b->attestation_types == NULL))
9377 {
9378 return(KMIP_FALSE);
9379 }
9380
9381 for(size_t i = 0; i < a->attestation_type_count; i++)
9382 {
9383 if(a->attestation_types[i] != b->attestation_types[i])
9384 {
9385 return(KMIP_FALSE);
9386 }
9387 }
9388 }
9389
9390 if(a->client_correlation_value != b->client_correlation_value)
9391 {
9392 if((a->client_correlation_value == NULL) || (b->client_correlation_value == NULL))
9393 {
9394 return(KMIP_FALSE);
9395 }
9396
9397 if(kmip_compare_text_string(a->client_correlation_value, b->client_correlation_value) == KMIP_FALSE)
9398 {
9399 return(KMIP_FALSE);
9400 }
9401 }
9402
9403 if(a->server_correlation_value != b->server_correlation_value)
9404 {
9405 if((a->server_correlation_value == NULL) || (b->server_correlation_value == NULL))
9406 {
9407 return(KMIP_FALSE);
9408 }
9409
9410 if(kmip_compare_text_string(a->server_correlation_value, b->server_correlation_value) == KMIP_FALSE)
9411 {
9412 return(KMIP_FALSE);
9413 }
9414 }
9415 }
9416
9417 return(KMIP_TRUE);
9418 }
9419
9420 int
9421 kmip_compare_request_message(const RequestMessage *a, const RequestMessage *b)
9422 {
9423 if(a != b)
9424 {
9425 if((a == NULL) || (b == NULL))
9426 {
9427 return(KMIP_FALSE);
9428 }
9429
9430 if(a->batch_count != b->batch_count)
9431 {
9432 return(KMIP_FALSE);
9433 }
9434
9435 if(a->request_header != b->request_header)
9436 {
9437 if((a->request_header == NULL) || (b->request_header == NULL))
9438 {
9439 return(KMIP_FALSE);
9440 }
9441
9442 if(kmip_compare_request_header(a->request_header, b->request_header) == KMIP_FALSE)
9443 {
9444 return(KMIP_FALSE);
9445 }
9446 }
9447
9448 if(a->batch_items != b->batch_items)
9449 {
9450 if((a->batch_items == NULL) || (b->batch_items == NULL))
9451 {
9452 return(KMIP_FALSE);
9453 }
9454
9455 for(size_t i = 0; i < a->batch_count; i++)
9456 {
9457 if(kmip_compare_request_batch_item(&a->batch_items[i], &b->batch_items[i]) == KMIP_FALSE)
9458 {
9459 return(KMIP_FALSE);
9460 }
9461 }
9462 }
9463 }
9464
9465 return(KMIP_TRUE);
9466 }
9467
9468 int
9469 kmip_compare_response_message(const ResponseMessage *a, const ResponseMessage *b)
9470 {
9471 if(a != b)
9472 {
9473 if((a == NULL) || (b == NULL))
9474 {
9475 return(KMIP_FALSE);
9476 }
9477
9478 if(a->batch_count != b->batch_count)
9479 {
9480 return(KMIP_FALSE);
9481 }
9482
9483 if(a->response_header != b->response_header)
9484 {
9485 if((a->response_header == NULL) || (b->response_header == NULL))
9486 {
9487 return(KMIP_FALSE);
9488 }
9489
9490 if(kmip_compare_response_header(a->response_header, b->response_header) == KMIP_FALSE)
9491 {
9492 return(KMIP_FALSE);
9493 }
9494 }
9495
9496 if(a->batch_items != b->batch_items)
9497 {
9498 if((a->batch_items == NULL) || (b->batch_items == NULL))
9499 {
9500 return(KMIP_FALSE);
9501 }
9502
9503 for(size_t i = 0; i < a->batch_count; i++)
9504 {
9505 if(kmip_compare_response_batch_item(&a->batch_items[i], &b->batch_items[i]) == KMIP_FALSE)
9506 {
9507 return(KMIP_FALSE);
9508 }
9509 }
9510 }
9511 }
9512
9513 return(KMIP_TRUE);
9514 }
9515
9516 int
9517 kmip_compare_linklist_items_int32(const LinkedListItem *a_item, const LinkedListItem *b_item)
9518 {
9519 while((a_item != NULL) && (b_item != NULL))
9520 {
9521 if(a_item != b_item)
9522 {
9523 int32 *a_data = (int32 *)a_item->data;
9524 int32 *b_data = (int32 *)b_item->data;
9525 if(a_data != b_data)
9526 {
9527 if((a_data == NULL) || (b_data == NULL))
9528 {
9529 return(KMIP_FALSE);
9530 }
9531 if(*a_data != *b_data)
9532 {
9533 return(KMIP_FALSE);
9534 }
9535 }
9536 }
9537
9538 a_item = a_item->next;
9539 b_item = b_item->next;
9540 }
9541
9542 if(a_item != b_item)
9543 {
9544 return(KMIP_FALSE);
9545 }
9546
9547 return(KMIP_TRUE);
9548 }
9549
9550 int
9551 kmip_compare_linklist_items_textstring(const LinkedListItem *a_item, const LinkedListItem *b_item)
9552 {
9553 while((a_item != NULL) && (b_item != NULL))
9554 {
9555 if(a_item != b_item)
9556 {
9557 TextString *a_data = (TextString *)a_item->data;
9558 TextString *b_data = (TextString *)b_item->data;
9559 if(kmip_compare_text_string(a_data, b_data) == KMIP_FALSE)
9560 {
9561 return(KMIP_FALSE);
9562 }
9563 }
9564
9565 a_item = a_item->next;
9566 b_item = b_item->next;
9567 }
9568
9569 if(a_item != b_item)
9570 {
9571 return(KMIP_FALSE);
9572 }
9573
9574 return(KMIP_TRUE);
9575 }
9576
9577 int
9578 kmip_compare_query_functions(const Functions* a, const Functions* b)
9579 {
9580 if(a != b )
9581 {
9582 if((a == NULL) || (b == NULL))
9583 {
9584 return(KMIP_FALSE);
9585 }
9586
9587 if((a->function_list != b->function_list))
9588 {
9589 if((a->function_list == NULL) || (b->function_list == NULL))
9590 {
9591 return(KMIP_FALSE);
9592 }
9593
9594 if((a->function_list->size != b->function_list->size))
9595 {
9596 return(KMIP_FALSE);
9597 }
9598
9599 LinkedListItem *a_item = a->function_list->head;
9600 LinkedListItem *b_item = b->function_list->head;
9601
9602 if (kmip_compare_linklist_items_int32(a_item, b_item) == KMIP_FALSE)
9603 {
9604 return(KMIP_FALSE);
9605 }
9606 }
9607 }
9608
9609 return(KMIP_TRUE);
9610 }
9611
9612 int
9613 kmip_compare_operations(const Operations *a, const Operations *b)
9614 {
9615 if(a != b)
9616 {
9617 if((a == NULL) || (b == NULL))
9618 {
9619 return(KMIP_FALSE);
9620 }
9621
9622 if((a->operation_list != b->operation_list))
9623 {
9624 if((a->operation_list == NULL) || (b->operation_list == NULL))
9625 {
9626 return(KMIP_FALSE);
9627 }
9628
9629 if((a->operation_list->size != b->operation_list->size))
9630 {
9631 return(KMIP_FALSE);
9632 }
9633
9634 LinkedListItem *a_item = a->operation_list->head;
9635 LinkedListItem *b_item = b->operation_list->head;
9636 if (kmip_compare_linklist_items_int32(a_item, b_item) == KMIP_FALSE)
9637 {
9638 return(KMIP_FALSE);
9639 }
9640 }
9641 }
9642
9643 return(KMIP_TRUE);
9644 }
9645
9646 int
9647 kmip_compare_objects(const ObjectTypes *a, const ObjectTypes *b)
9648 {
9649 if(a != b)
9650 {
9651 if((a == NULL) || (b == NULL))
9652 {
9653 return(KMIP_FALSE);
9654 }
9655
9656 if((a->object_list != b->object_list))
9657 {
9658 if((a->object_list == NULL) || (b->object_list == NULL))
9659 {
9660 return(KMIP_FALSE);
9661 }
9662
9663 if((a->object_list->size != b->object_list->size))
9664 {
9665 return(KMIP_FALSE);
9666 }
9667
9668 LinkedListItem *a_item = a->object_list->head;
9669 LinkedListItem *b_item = b->object_list->head;
9670 if (kmip_compare_linklist_items_int32(a_item, b_item) == KMIP_FALSE)
9671 {
9672 return(KMIP_FALSE);
9673 }
9674 }
9675 }
9676
9677 return(KMIP_TRUE);
9678 }
9679
9680 int
9681 kmip_compare_alternative_endpoints(const AltEndpoints* a, const AltEndpoints* b)
9682 {
9683 if(a != b)
9684 {
9685 if((a == NULL) || (b == NULL))
9686 {
9687 return(KMIP_FALSE);
9688 }
9689
9690 if((a->endpoint_list != b->endpoint_list))
9691 {
9692 if((a->endpoint_list == NULL) || (b->endpoint_list == NULL))
9693 {
9694 return(KMIP_FALSE);
9695 }
9696
9697 if((a->endpoint_list->size != b->endpoint_list->size))
9698 {
9699 return(KMIP_FALSE);
9700 }
9701
9702 LinkedListItem *a_item = a->endpoint_list->head;
9703 LinkedListItem *b_item = b->endpoint_list->head;
9704 if (kmip_compare_linklist_items_textstring(a_item, b_item) == KMIP_FALSE)
9705 {
9706 return(KMIP_FALSE);
9707 }
9708 }
9709 }
9710
9711 return(KMIP_TRUE);
9712 }
9713
9714 int
9715 kmip_compare_server_information(const ServerInformation* a, const ServerInformation* b)
9716 {
9717 if(a != b)
9718 {
9719 if((a == NULL) || (b == NULL))
9720 {
9721 return(KMIP_FALSE);
9722 }
9723
9724 if(kmip_compare_text_string(a->server_name, b->server_name) == KMIP_FALSE)
9725 {
9726 return(KMIP_FALSE);
9727 }
9728
9729 if(kmip_compare_text_string(a->server_serial_number, b->server_serial_number) == KMIP_FALSE)
9730 {
9731 return(KMIP_FALSE);
9732 }
9733
9734 if(kmip_compare_text_string(a->server_version, b->server_version) == KMIP_FALSE)
9735 {
9736 return(KMIP_FALSE);
9737 }
9738
9739 if(kmip_compare_text_string(a->server_load, b->server_load) == KMIP_FALSE)
9740 {
9741 return(KMIP_FALSE);
9742 }
9743 if(kmip_compare_text_string(a->product_name, b->product_name) == KMIP_FALSE)
9744 {
9745 return(KMIP_FALSE);
9746 }
9747 if(kmip_compare_text_string(a->build_level, b->build_level) == KMIP_FALSE)
9748 {
9749 return(KMIP_FALSE);
9750 }
9751 if(kmip_compare_text_string(a->build_date, b->build_date) == KMIP_FALSE)
9752 {
9753 return(KMIP_FALSE);
9754 }
9755
9756 if(a->alternative_failover_endpoints != b->alternative_failover_endpoints )
9757 {
9758 if(kmip_compare_alternative_endpoints(a->alternative_failover_endpoints, b->alternative_failover_endpoints) == KMIP_FALSE)
9759 {
9760 return(KMIP_FALSE);
9761 }
9762 }
9763
9764 // if(a->vendor_specific != b->vendor_specific )
9765 // {
9766 // if(kmip_compare_vendor_specifi(a->vendor_specific, b->vendor_specific) == KMIP_FALSE)
9767 // {
9768 // return(KMIP_FALSE);
9769 // }
9770 // }
9771
9772 }
9773
9774 return(KMIP_TRUE);
9775 }
9776
9777 int
9778 kmip_compare_query_request_payload(const QueryRequestPayload *a, const QueryRequestPayload *b)
9779 {
9780 if(a != b)
9781 {
9782 if((a == NULL) || (b == NULL))
9783 {
9784 return(KMIP_FALSE);
9785 }
9786
9787 if(a->functions != b->functions)
9788 {
9789 if((a->functions == NULL) || (b->functions == NULL))
9790 {
9791 return(KMIP_FALSE);
9792 }
9793
9794 if(kmip_compare_query_functions(a->functions, b->functions) == KMIP_FALSE)
9795 {
9796 return(KMIP_FALSE);
9797 }
9798 }
9799 }
9800
9801 return(KMIP_TRUE);
9802 }
9803
9804 int
9805 kmip_compare_query_response_payload(const QueryResponsePayload *a, const QueryResponsePayload *b)
9806 {
9807 if(a != b)
9808 {
9809 if((a == NULL) || (b == NULL))
9810 {
9811 return(KMIP_FALSE);
9812 }
9813
9814 if(a->operations != b->operations)
9815 {
9816 if((a->operations == NULL) || (b->operations == NULL))
9817 {
9818 return(KMIP_FALSE);
9819 }
9820
9821 if(kmip_compare_operations(a->operations, b->operations) == KMIP_FALSE)
9822 {
9823 return(KMIP_FALSE);
9824 }
9825 }
9826
9827 if(a->objects != b->objects)
9828 {
9829 if((a->objects == NULL) || (b->objects == NULL))
9830 {
9831 return(KMIP_FALSE);
9832 }
9833
9834 if(kmip_compare_objects(a->objects, b->objects) == KMIP_FALSE)
9835 {
9836 return(KMIP_FALSE);
9837 }
9838 }
9839
9840 if(a->vendor_identification != b->vendor_identification)
9841 {
9842 if((a->vendor_identification == NULL) || (b->vendor_identification == NULL))
9843 {
9844 return(KMIP_FALSE);
9845 }
9846
9847 if(kmip_compare_text_string(a->vendor_identification, b->vendor_identification) == KMIP_FALSE)
9848 {
9849 return(KMIP_FALSE);
9850 }
9851 }
9852
9853 if(a->server_information != b->server_information)
9854 {
9855 if((a->server_information == NULL) || (b->server_information == NULL))
9856 {
9857 return(KMIP_FALSE);
9858 }
9859
9860 if(kmip_compare_server_information(a->server_information, b->server_information) == KMIP_FALSE)
9861 {
9862 return(KMIP_FALSE);
9863 }
9864 }
9865 }
9866
9867 return(KMIP_TRUE);
9868 }
9869
9870
9871 /*
9872 Encoding Functions
9873 */
9874
9875 int
9876 kmip_encode_int8_be(KMIP *ctx, int8 value)
9877 {
9878 CHECK_BUFFER_FULL(ctx, sizeof(int8));
9879
9880 uint8 v = *(uint8 *)((void *)(&value));
9881
9882 *ctx->index++ = v;
9883
9884 return(KMIP_OK);
9885 }
9886
9887 int
9888 kmip_encode_int32_be(KMIP *ctx, int32 value)
9889 {
9890 CHECK_BUFFER_FULL(ctx, sizeof(int32));
9891
9892 uint32 v = *(uint32 *)((void *)(&value));
9893
9894 *ctx->index++ = (uint8)((v & 0xFF000000) >> 24);
9895 *ctx->index++ = (uint8)((v & 0x00FF0000) >> 16);
9896 *ctx->index++ = (uint8)((v & 0x0000FF00) >> 8);
9897 *ctx->index++ = (uint8)((v & 0x000000FF) >> 0);
9898
9899 return(KMIP_OK);
9900 }
9901
9902 int
9903 kmip_encode_int64_be(KMIP *ctx, int64 value)
9904 {
9905 CHECK_BUFFER_FULL(ctx, sizeof(int64));
9906
9907 uint64 v = *(uint64 *)((void *)(&value));
9908
9909 *ctx->index++ = (uint8)((v & 0xFF00000000000000) >> 56);
9910 *ctx->index++ = (uint8)((v & 0x00FF000000000000) >> 48);
9911 *ctx->index++ = (uint8)((v & 0x0000FF0000000000) >> 40);
9912 *ctx->index++ = (uint8)((v & 0x000000FF00000000) >> 32);
9913 *ctx->index++ = (uint8)((v & 0x00000000FF000000) >> 24);
9914 *ctx->index++ = (uint8)((v & 0x0000000000FF0000) >> 16);
9915 *ctx->index++ = (uint8)((v & 0x000000000000FF00) >> 8);
9916 *ctx->index++ = (uint8)((v & 0x00000000000000FF) >> 0);
9917
9918 return(KMIP_OK);
9919 }
9920
9921 int
9922 kmip_encode_integer(KMIP *ctx, enum tag t, int32 value)
9923 {
9924 CHECK_BUFFER_FULL(ctx, 16);
9925
9926 kmip_encode_int32_be(ctx, TAG_TYPE(t, KMIP_TYPE_INTEGER));
9927 kmip_encode_int32_be(ctx, 4);
9928 kmip_encode_int32_be(ctx, value);
9929 kmip_encode_int32_be(ctx, 0);
9930
9931 return(KMIP_OK);
9932 }
9933
9934 int
9935 kmip_encode_long(KMIP *ctx, enum tag t, int64 value)
9936 {
9937 CHECK_BUFFER_FULL(ctx, 16);
9938
9939 kmip_encode_int32_be(ctx, TAG_TYPE(t, KMIP_TYPE_LONG_INTEGER));
9940 kmip_encode_int32_be(ctx, 8);
9941 kmip_encode_int64_be(ctx, value);
9942
9943 return(KMIP_OK);
9944 }
9945
9946 int
9947 kmip_encode_enum(KMIP *ctx, enum tag t, int32 value)
9948 {
9949 CHECK_BUFFER_FULL(ctx, 16);
9950
9951 kmip_encode_int32_be(ctx, TAG_TYPE(t, KMIP_TYPE_ENUMERATION));
9952 kmip_encode_int32_be(ctx, 4);
9953 kmip_encode_int32_be(ctx, value);
9954 kmip_encode_int32_be(ctx, 0);
9955
9956 return(KMIP_OK);
9957 }
9958
9959 int
9960 kmip_encode_bool(KMIP *ctx, enum tag t, bool32 value)
9961 {
9962 CHECK_BUFFER_FULL(ctx, 16);
9963
9964 kmip_encode_int32_be(ctx, TAG_TYPE(t, KMIP_TYPE_BOOLEAN));
9965 kmip_encode_int32_be(ctx, 8);
9966 kmip_encode_int32_be(ctx, 0);
9967 kmip_encode_int32_be(ctx, value);
9968
9969 return(KMIP_OK);
9970 }
9971
9972 int
9973 kmip_encode_text_string(KMIP *ctx, enum tag t, const TextString *value)
9974 {
9975 /* TODO (ph) What if value is NULL? */
9976 uint8 padding = CALCULATE_PADDING(value->size);
9977 CHECK_BUFFER_FULL(ctx, 8 + value->size + padding);
9978
9979 kmip_encode_int32_be(ctx, TAG_TYPE(t, KMIP_TYPE_TEXT_STRING));
9980 kmip_encode_int32_be(ctx, value->size);
9981
9982 for(uint32 i = 0; i < value->size; i++)
9983 {
9984 kmip_encode_int8_be(ctx, value->value[i]);
9985 }
9986 for(uint8 i = 0; i < padding; i++)
9987 {
9988 kmip_encode_int8_be(ctx, 0);
9989 }
9990
9991 return(KMIP_OK);
9992 }
9993
9994 int
9995 kmip_encode_byte_string(KMIP *ctx, enum tag t, const ByteString *value)
9996 {
9997 uint8 padding = CALCULATE_PADDING(value->size);
9998 CHECK_BUFFER_FULL(ctx, 8 + value->size + padding);
9999
10000 kmip_encode_int32_be(ctx, TAG_TYPE(t, KMIP_TYPE_BYTE_STRING));
10001 kmip_encode_int32_be(ctx, value->size);
10002
10003 for(uint32 i = 0; i < value->size; i++)
10004 {
10005 kmip_encode_int8_be(ctx, value->value[i]);
10006 }
10007 for(uint8 i = 0; i < padding; i++)
10008 {
10009 kmip_encode_int8_be(ctx, 0);
10010 }
10011
10012 return(KMIP_OK);
10013 }
10014
10015 int
10016 kmip_encode_date_time(KMIP *ctx, enum tag t, int64 value)
10017 {
10018 CHECK_BUFFER_FULL(ctx, 16);
10019
10020 kmip_encode_int32_be(ctx, TAG_TYPE(t, KMIP_TYPE_DATE_TIME));
10021 kmip_encode_int32_be(ctx, 8);
10022 kmip_encode_int64_be(ctx, value);
10023
10024 return(KMIP_OK);
10025 }
10026
10027 int
10028 kmip_encode_interval(KMIP *ctx, enum tag t, uint32 value)
10029 {
10030 CHECK_BUFFER_FULL(ctx, 16);
10031
10032 kmip_encode_int32_be(ctx, TAG_TYPE(t, KMIP_TYPE_INTERVAL));
10033 kmip_encode_int32_be(ctx, 4);
10034 kmip_encode_int32_be(ctx, value);
10035 kmip_encode_int32_be(ctx, 0);
10036
10037 return(KMIP_OK);
10038 }
10039
10040 int
10041 kmip_encode_length(KMIP *ctx, intptr length)
10042 {
10043 // NOTE: Length is encoded as a signed 32-bit integer but the usage of this
10044 // function uses the difference between two buffer pointers to determine
10045 // the length in bytes that should be encoded. See the intptr typedef in
10046 // the header for type details.
10047 int result = 0;
10048
10049 if((length > INT_MAX) || (length < 0))
10050 {
10051 HANDLE_FAILURE(ctx, KMIP_INVALID_LENGTH);
10052 }
10053 else
10054 {
10055 result = kmip_encode_int32_be(ctx, (int32)length);
10056 CHECK_RESULT(ctx, result);
10057 }
10058
10059 return(KMIP_OK);
10060 }
10061
10062 int
10063 kmip_encode_name(KMIP *ctx, const Name *value)
10064 {
10065 /* TODO (ph) Check for value == NULL? */
10066
10067 int result = 0;
10068
10069 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_NAME, KMIP_TYPE_STRUCTURE));
10070 CHECK_RESULT(ctx, result);
10071
10072 uint8 *length_index = ctx->index;
10073 uint8 *value_index = ctx->index += 4;
10074
10075 result = kmip_encode_text_string(ctx, KMIP_TAG_NAME_VALUE, value->value);
10076 CHECK_RESULT(ctx, result);
10077
10078 result = kmip_encode_enum(ctx, KMIP_TAG_NAME_TYPE, value->type);
10079 CHECK_RESULT(ctx, result);
10080
10081 uint8 *curr_index = ctx->index;
10082 ctx->index = length_index;
10083
10084 result = kmip_encode_length(ctx, curr_index - value_index);
10085 CHECK_RESULT(ctx, result);
10086
10087 ctx->index = curr_index;
10088
10089 return(KMIP_OK);
10090 }
10091
10092 int
10093 kmip_encode_protection_storage_masks(KMIP *ctx, const ProtectionStorageMasks *value)
10094 {
10095 CHECK_ENCODE_ARGS(ctx, value);
10096 CHECK_KMIP_VERSION(ctx, KMIP_2_0);
10097
10098 int result = 0;
10099
10100 result = kmip_encode_int32_be(
10101 ctx,
10102 TAG_TYPE(KMIP_TAG_PROTECTION_STORAGE_MASKS, KMIP_TYPE_STRUCTURE)
10103 );
10104 CHECK_RESULT(ctx, result);
10105
10106 uint8 *length_index = ctx->index;
10107 uint8 *value_index = ctx->index += 4;
10108
10109 if(value->masks != NULL)
10110 {
10111 LinkedListItem *curr = value->masks->head;
10112 while(curr != NULL)
10113 {
10114 result = kmip_encode_integer(ctx, KMIP_TAG_PROTECTION_STORAGE_MASK, *(int32 *)curr->data);
10115 CHECK_RESULT(ctx, result);
10116
10117 curr = curr->next;
10118 }
10119 }
10120
10121 uint8 *curr_index = ctx->index;
10122 ctx->index = length_index;
10123
10124 result = kmip_encode_length(ctx, curr_index - value_index);
10125 CHECK_RESULT(ctx, result);
10126
10127 ctx->index = curr_index;
10128
10129 return(KMIP_OK);
10130 }
10131
10132 int
10133 kmip_encode_attribute_name(KMIP *ctx, enum attribute_type value)
10134 {
10135 int result = 0;
10136 enum tag t = KMIP_TAG_ATTRIBUTE_NAME;
10137 TextString attribute_name = {0};
10138
10139 switch(value)
10140 {
10141 case KMIP_ATTR_UNIQUE_IDENTIFIER:
10142 attribute_name.value = "Unique Identifier";
10143 attribute_name.size = 17;
10144 break;
10145
10146 case KMIP_ATTR_NAME:
10147 attribute_name.value = "Name";
10148 attribute_name.size = 4;
10149 break;
10150
10151 case KMIP_ATTR_OBJECT_TYPE:
10152 attribute_name.value = "Object Type";
10153 attribute_name.size = 11;
10154 break;
10155
10156 case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
10157 attribute_name.value = "Cryptographic Algorithm";
10158 attribute_name.size = 23;
10159 break;
10160
10161 case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
10162 attribute_name.value = "Cryptographic Length";
10163 attribute_name.size = 20;
10164 break;
10165
10166 case KMIP_ATTR_OPERATION_POLICY_NAME:
10167 attribute_name.value = "Operation Policy Name";
10168 attribute_name.size = 21;
10169 break;
10170
10171 case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
10172 attribute_name.value = "Cryptographic Usage Mask";
10173 attribute_name.size = 24;
10174 break;
10175
10176 case KMIP_ATTR_STATE:
10177 attribute_name.value = "State";
10178 attribute_name.size = 5;
10179 break;
10180
10181 case KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION:
10182 {
10183 attribute_name.value = "Application Specific Information";
10184 attribute_name.size = 32;
10185 }
10186 break;
10187
10188 case KMIP_ATTR_OBJECT_GROUP:
10189 {
10190 attribute_name.value = "Object Group";
10191 attribute_name.size = 12;
10192 }
10193 break;
10194
10195 case KMIP_ATTR_ACTIVATION_DATE:
10196 {
10197 attribute_name.value = "Activation Date";
10198 attribute_name.size = 15;
10199 } break;
10200
10201 case KMIP_ATTR_DEACTIVATION_DATE:
10202 {
10203 attribute_name.value = "Deactivation Date";
10204 attribute_name.size = 17;
10205 } break;
10206
10207 case KMIP_ATTR_PROCESS_START_DATE:
10208 {
10209 attribute_name.value = "Process Start Date";
10210 attribute_name.size = 18;
10211 } break;
10212
10213 case KMIP_ATTR_PROTECT_STOP_DATE:
10214 {
10215 attribute_name.value = "Protect Stop Date";
10216 attribute_name.size = 17;
10217 } break;
10218
10219 case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
10220 {
10221 attribute_name.value = "Cryptographic Parameters";
10222 attribute_name.size = 24;
10223 } break;
10224
10225 default:
10226 kmip_push_error_frame(ctx, __func__, __LINE__);
10227 return(KMIP_ERROR_ATTR_UNSUPPORTED);
10228 break;
10229 };
10230
10231 result = kmip_encode_text_string(ctx, t, &attribute_name);
10232 CHECK_RESULT(ctx, result);
10233
10234 return(KMIP_OK);
10235 }
10236
10237 int
10238 kmip_encode_attribute_v1(KMIP *ctx, const Attribute *value)
10239 {
10240 /* TODO (ph) Add CryptographicParameters support? */
10241 CHECK_ENCODE_ARGS(ctx, value);
10242
10243 int result = 0;
10244
10245 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE, KMIP_TYPE_STRUCTURE));
10246 CHECK_RESULT(ctx, result);
10247
10248 uint8 *length_index = ctx->index;
10249 uint8 *value_index = ctx->index += 4;
10250
10251 result = kmip_encode_attribute_name(ctx, value->type);
10252 CHECK_RESULT(ctx, result);
10253
10254 if(value->index != KMIP_UNSET)
10255 {
10256 result = kmip_encode_integer(ctx, KMIP_TAG_ATTRIBUTE_INDEX, value->index);
10257 CHECK_RESULT(ctx, result);
10258 }
10259
10260 uint8 *curr_index = 0;
10261 uint8 *tag_index = ctx->index;
10262 enum tag t = KMIP_TAG_ATTRIBUTE_VALUE;
10263
10264 switch(value->type)
10265 {
10266 case KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION:
10267 {
10268 result = kmip_encode_application_specific_information(ctx, (ApplicationSpecificInformation*)value->value);
10269 CHECK_RESULT(ctx, result);
10270
10271 curr_index = ctx->index;
10272 ctx->index = tag_index;
10273
10274 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE));
10275
10276 ctx->index = curr_index;
10277 }
10278 break;
10279
10280 case KMIP_ATTR_UNIQUE_IDENTIFIER:
10281 result = kmip_encode_text_string(ctx, t, (TextString*)value->value);
10282 break;
10283
10284 case KMIP_ATTR_NAME:
10285 /* TODO (ph) This is messy. Clean it up? */
10286 result = kmip_encode_name(ctx, (Name*)value->value);
10287 CHECK_RESULT(ctx, result);
10288
10289 curr_index = ctx->index;
10290 ctx->index = tag_index;
10291
10292 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE));
10293
10294 ctx->index = curr_index;
10295 break;
10296
10297 case KMIP_ATTR_OBJECT_TYPE:
10298 result = kmip_encode_enum(ctx, t, *(int32 *)value->value);
10299 break;
10300
10301 case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
10302 result = kmip_encode_enum(ctx, t, *(int32 *)value->value);
10303 break;
10304
10305 case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
10306 result = kmip_encode_integer(ctx, t, *(int32 *)value->value);
10307 break;
10308
10309 case KMIP_ATTR_OPERATION_POLICY_NAME:
10310 result = kmip_encode_text_string(ctx, t, (TextString*)value->value);
10311 break;
10312
10313 case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
10314 result = kmip_encode_integer(ctx, t, *(int32 *)value->value);
10315 break;
10316
10317 case KMIP_ATTR_STATE:
10318 result = kmip_encode_enum(ctx, t, *(int32 *)value->value);
10319 break;
10320
10321 case KMIP_ATTR_OBJECT_GROUP:
10322 {
10323 result = kmip_encode_text_string(ctx, t, (TextString*)value->value);
10324 }
10325 break;
10326
10327 case KMIP_ATTR_ACTIVATION_DATE:
10328 case KMIP_ATTR_DEACTIVATION_DATE:
10329 case KMIP_ATTR_PROCESS_START_DATE:
10330 case KMIP_ATTR_PROTECT_STOP_DATE:
10331 {
10332 result = kmip_encode_date_time(ctx, t, *(int64 *)value->value);
10333 } break;
10334
10335 case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
10336 {
10337 result = kmip_encode_cryptographic_parameters(ctx, (CryptographicParameters*)value->value);
10338 CHECK_RESULT(ctx, result);
10339
10340 curr_index = ctx->index;
10341 ctx->index = tag_index;
10342
10343 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE));
10344
10345 ctx->index = curr_index;
10346 } break;
10347
10348 default:
10349 kmip_push_error_frame(ctx, __func__, __LINE__);
10350 return(KMIP_ERROR_ATTR_UNSUPPORTED);
10351 break;
10352 };
10353 CHECK_RESULT(ctx, result);
10354
10355 curr_index = ctx->index;
10356 ctx->index = length_index;
10357
10358 result = kmip_encode_length(ctx, curr_index - value_index);
10359 CHECK_RESULT(ctx, result);
10360
10361 ctx->index = curr_index;
10362
10363 return(KMIP_OK);
10364 }
10365
10366 int
10367 kmip_encode_attribute_v2(KMIP *ctx, const Attribute *value)
10368 {
10369 CHECK_ENCODE_ARGS(ctx, value);
10370
10371 int result = 0;
10372
10373 switch(value->type)
10374 {
10375 case KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION:
10376 {
10377 result = kmip_encode_application_specific_information(
10378 ctx,
10379 (ApplicationSpecificInformation*)value->value
10380 );
10381 }
10382 break;
10383
10384 case KMIP_ATTR_UNIQUE_IDENTIFIER:
10385 {
10386 result = kmip_encode_text_string(
10387 ctx,
10388 KMIP_TAG_UNIQUE_IDENTIFIER,
10389 (TextString*)value->value
10390 );
10391 }
10392 break;
10393
10394 case KMIP_ATTR_NAME:
10395 {
10396 result = kmip_encode_name(ctx, (Name*)value->value);
10397 }
10398 break;
10399
10400 case KMIP_ATTR_OBJECT_TYPE:
10401 {
10402 result = kmip_encode_enum(
10403 ctx,
10404 KMIP_TAG_OBJECT_TYPE,
10405 *(int32 *)value->value
10406 );
10407 }
10408 break;
10409
10410 case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
10411 {
10412 result = kmip_encode_enum(
10413 ctx,
10414 KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM,
10415 *(int32 *)value->value
10416 );
10417 }
10418 break;
10419
10420 case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
10421 {
10422 result = kmip_encode_integer(
10423 ctx,
10424 KMIP_TAG_CRYPTOGRAPHIC_LENGTH,
10425 *(int32 *)value->value
10426 );
10427 }
10428 break;
10429
10430 case KMIP_ATTR_OPERATION_POLICY_NAME:
10431 {
10432 result = kmip_encode_text_string(
10433 ctx,
10434 KMIP_TAG_OPERATION_POLICY_NAME,
10435 (TextString*)value->value
10436 );
10437 }
10438 break;
10439
10440 case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
10441 {
10442 result = kmip_encode_integer(
10443 ctx,
10444 KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK,
10445 *(int32 *)value->value)
10446 ;
10447 }
10448 break;
10449
10450 case KMIP_ATTR_STATE:
10451 {
10452 result = kmip_encode_enum(
10453 ctx,
10454 KMIP_TAG_STATE,
10455 *(int32 *)value->value
10456 );
10457 }
10458 break;
10459
10460 case KMIP_ATTR_OBJECT_GROUP:
10461 {
10462 result = kmip_encode_text_string(
10463 ctx,
10464 KMIP_TAG_OBJECT_GROUP,
10465 (TextString*)value->value
10466 );
10467 }
10468 break;
10469
10470 case KMIP_ATTR_ACTIVATION_DATE:
10471 {
10472 result = kmip_encode_date_time(
10473 ctx,
10474 KMIP_TAG_ACTIVATION_DATE,
10475 *(int64 *)value->value
10476 );
10477 } break;
10478
10479 case KMIP_ATTR_DEACTIVATION_DATE:
10480 {
10481 result = kmip_encode_date_time(
10482 ctx,
10483 KMIP_TAG_DEACTIVATION_DATE,
10484 *(int64 *)value->value
10485 );
10486 } break;
10487
10488 case KMIP_ATTR_PROCESS_START_DATE:
10489 {
10490 result = kmip_encode_date_time(
10491 ctx,
10492 KMIP_TAG_PROCESS_START_DATE,
10493 *(int64 *)value->value
10494 );
10495 } break;
10496
10497 case KMIP_ATTR_PROTECT_STOP_DATE:
10498 {
10499 result = kmip_encode_date_time(
10500 ctx,
10501 KMIP_TAG_PROTECT_STOP_DATE,
10502 *(int64 *)value->value
10503 );
10504 } break;
10505
10506 case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
10507 {
10508 result = kmip_encode_cryptographic_parameters(
10509 ctx,
10510 (CryptographicParameters*)value->value
10511 );
10512 } break;
10513
10514 default:
10515 {
10516 kmip_push_error_frame(ctx, __func__, __LINE__);
10517 return(KMIP_ERROR_ATTR_UNSUPPORTED);
10518 }
10519 break;
10520 };
10521 CHECK_RESULT(ctx, result);
10522
10523 return(KMIP_OK);
10524 }
10525
10526 int
10527 kmip_encode_attribute(KMIP *ctx, const Attribute *value)
10528 {
10529 CHECK_ENCODE_ARGS(ctx, value);
10530
10531 if(ctx->version < KMIP_2_0)
10532 {
10533 return(kmip_encode_attribute_v1(ctx, value));
10534 }
10535 else
10536 {
10537 return(kmip_encode_attribute_v2(ctx, value));
10538 }
10539 }
10540
10541 int
10542 kmip_encode_attributes(KMIP *ctx, const Attributes *value)
10543 {
10544 CHECK_ENCODE_ARGS(ctx, value);
10545 CHECK_KMIP_VERSION(ctx, KMIP_2_0);
10546
10547 int result = 0;
10548
10549 result = kmip_encode_int32_be(
10550 ctx,
10551 TAG_TYPE(KMIP_TAG_ATTRIBUTES, KMIP_TYPE_STRUCTURE)
10552 );
10553 CHECK_RESULT(ctx, result);
10554
10555 uint8 *length_index = ctx->index;
10556 uint8 *value_index = ctx->index += 4;
10557
10558 if(value->attribute_list != NULL)
10559 {
10560 LinkedListItem *curr = value->attribute_list->head;
10561 while(curr != NULL)
10562 {
10563 Attribute *attribute = (Attribute *)curr->data;
10564 result = kmip_encode_attribute(ctx, attribute);
10565 CHECK_RESULT(ctx, result);
10566
10567 curr = curr->next;
10568 }
10569 }
10570
10571 uint8 *curr_index = ctx->index;
10572 ctx->index = length_index;
10573
10574 result = kmip_encode_length(ctx, curr_index - value_index);
10575 CHECK_RESULT(ctx, result);
10576
10577 ctx->index = curr_index;
10578
10579 return(KMIP_OK);
10580 }
10581
10582 int
10583 kmip_encode_template_attribute(KMIP *ctx, const TemplateAttribute *value)
10584 {
10585 int result = 0;
10586
10587 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_TEMPLATE_ATTRIBUTE, KMIP_TYPE_STRUCTURE));
10588 CHECK_RESULT(ctx, result);
10589
10590 uint8 *length_index = ctx->index;
10591 uint8 *value_index = ctx->index += 4;
10592
10593 for(size_t i = 0; i < value->name_count; i++)
10594 {
10595 result = kmip_encode_name(ctx, &value->names[i]);
10596 CHECK_RESULT(ctx, result);
10597 }
10598
10599 for(size_t i = 0; i <value->attribute_count; i++)
10600 {
10601 result = kmip_encode_attribute(ctx, &value->attributes[i]);
10602 CHECK_RESULT(ctx, result);
10603 }
10604
10605 uint8 *curr_index = ctx->index;
10606 ctx->index = length_index;
10607
10608 result = kmip_encode_length(ctx, curr_index - value_index);
10609 CHECK_RESULT(ctx, result);
10610
10611 ctx->index = curr_index;
10612
10613 return(KMIP_OK);
10614 }
10615
10616 int
10617 kmip_encode_protocol_version(KMIP *ctx, const ProtocolVersion *value)
10618 {
10619 CHECK_BUFFER_FULL(ctx, 40);
10620
10621 kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_PROTOCOL_VERSION, KMIP_TYPE_STRUCTURE));
10622
10623 uint8 *length_index = ctx->index;
10624 uint8 *value_index = ctx->index += 4;
10625
10626 kmip_encode_integer(ctx, KMIP_TAG_PROTOCOL_VERSION_MAJOR, value->major);
10627 kmip_encode_integer(ctx, KMIP_TAG_PROTOCOL_VERSION_MINOR, value->minor);
10628
10629 uint8 *curr_index = ctx->index;
10630 ctx->index = length_index;
10631
10632 kmip_encode_length(ctx, curr_index - value_index);
10633
10634 ctx->index = curr_index;
10635
10636 return(KMIP_OK);
10637 }
10638
10639 int
10640 kmip_encode_application_specific_information(KMIP *ctx, const ApplicationSpecificInformation *value)
10641 {
10642 int result = 0;
10643 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_APPLICATION_SPECIFIC_INFORMATION, KMIP_TYPE_STRUCTURE));
10644 CHECK_RESULT(ctx, result);
10645
10646 uint8 *length_index = ctx->index;
10647 uint8 *value_index = ctx->index += 4;
10648
10649 if(value->application_namespace != NULL)
10650 {
10651 result = kmip_encode_text_string(ctx, KMIP_TAG_APPLICATION_NAMESPACE, value->application_namespace);
10652 CHECK_RESULT(ctx, result);
10653 }
10654 else
10655 {
10656 kmip_set_error_message(ctx, "The ApplicationSpecificInformation structure is missing the application name field.");
10657 kmip_push_error_frame(ctx, __func__, __LINE__);
10658 return(KMIP_INVALID_FIELD);
10659 }
10660
10661 if(value->application_data != NULL)
10662 {
10663 result = kmip_encode_text_string(ctx, KMIP_TAG_APPLICATION_DATA, value->application_data);
10664 CHECK_RESULT(ctx, result);
10665 }
10666 else
10667 {
10668 if(ctx->version < KMIP_1_3)
10669 {
10670 kmip_set_error_message(ctx, "The ApplicationSpecificInformation structure is missing the application data field.");
10671 kmip_push_error_frame(ctx, __func__, __LINE__);
10672 return(KMIP_INVALID_FIELD);
10673 }
10674 }
10675
10676 uint8 *curr_index = ctx->index;
10677 ctx->index = length_index;
10678
10679 result = kmip_encode_length(ctx, curr_index - value_index);
10680 CHECK_RESULT(ctx, result);
10681
10682 ctx->index = curr_index;
10683
10684 return(KMIP_OK);
10685 }
10686
10687 int
10688 kmip_encode_cryptographic_parameters(KMIP *ctx, const CryptographicParameters *value)
10689 {
10690 int result = 0;
10691 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_CRYPTOGRAPHIC_PARAMETERS, KMIP_TYPE_STRUCTURE));
10692 CHECK_RESULT(ctx, result);
10693
10694 uint8 *length_index = ctx->index;
10695 uint8 *value_index = ctx->index += 4;
10696
10697 if(value->block_cipher_mode != 0)
10698 {
10699 result = kmip_encode_enum(ctx, KMIP_TAG_BLOCK_CIPHER_MODE, value->block_cipher_mode);
10700 CHECK_RESULT(ctx, result);
10701 }
10702
10703 if(value->padding_method != 0)
10704 {
10705 result = kmip_encode_enum(ctx, KMIP_TAG_PADDING_METHOD, value->padding_method);
10706 CHECK_RESULT(ctx, result);
10707 }
10708
10709 if(value->hashing_algorithm != 0)
10710 {
10711 result = kmip_encode_enum(ctx, KMIP_TAG_HASHING_ALGORITHM, value->hashing_algorithm);
10712 CHECK_RESULT(ctx, result);
10713 }
10714
10715 if(value->key_role_type != 0)
10716 {
10717 result = kmip_encode_enum(ctx, KMIP_TAG_KEY_ROLE_TYPE, value->key_role_type);
10718 CHECK_RESULT(ctx, result);
10719 }
10720
10721 if(ctx->version >= KMIP_1_2)
10722 {
10723 if(value->digital_signature_algorithm != 0)
10724 {
10725 result = kmip_encode_enum(ctx, KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM, value->digital_signature_algorithm);
10726 CHECK_RESULT(ctx, result);
10727 }
10728
10729 if(value->cryptographic_algorithm != 0)
10730 {
10731 result = kmip_encode_enum(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM, value->cryptographic_algorithm);
10732 CHECK_RESULT(ctx, result);
10733 }
10734
10735 if(value->random_iv != KMIP_UNSET)
10736 {
10737 result = kmip_encode_bool(ctx, KMIP_TAG_RANDOM_IV, value->random_iv);
10738 CHECK_RESULT(ctx, result);
10739 }
10740
10741 if(value->iv_length != KMIP_UNSET)
10742 {
10743 result = kmip_encode_integer(ctx, KMIP_TAG_IV_LENGTH, value->iv_length);
10744 CHECK_RESULT(ctx, result);
10745 }
10746
10747 if(value->tag_length != KMIP_UNSET)
10748 {
10749 result = kmip_encode_integer(ctx, KMIP_TAG_TAG_LENGTH, value->tag_length);
10750 CHECK_RESULT(ctx, result);
10751 }
10752
10753 if(value->fixed_field_length != KMIP_UNSET)
10754 {
10755 result = kmip_encode_integer(ctx, KMIP_TAG_FIXED_FIELD_LENGTH, value->fixed_field_length);
10756 CHECK_RESULT(ctx, result);
10757 }
10758
10759 if(value->invocation_field_length != KMIP_UNSET)
10760 {
10761 result = kmip_encode_integer(ctx, KMIP_TAG_INVOCATION_FIELD_LENGTH, value->invocation_field_length);
10762 CHECK_RESULT(ctx, result);
10763 }
10764
10765 if(value->counter_length != KMIP_UNSET)
10766 {
10767 result = kmip_encode_integer(ctx, KMIP_TAG_COUNTER_LENGTH, value->counter_length);
10768 CHECK_RESULT(ctx, result);
10769 }
10770
10771 if(value->initial_counter_value != KMIP_UNSET)
10772 {
10773 result = kmip_encode_integer(ctx, KMIP_TAG_INITIAL_COUNTER_VALUE, value->initial_counter_value);
10774 CHECK_RESULT(ctx, result);
10775 }
10776 }
10777
10778 if(ctx->version >= KMIP_1_4)
10779 {
10780 if(value->salt_length != KMIP_UNSET)
10781 {
10782 result = kmip_encode_integer(ctx, KMIP_TAG_SALT_LENGTH, value->salt_length);
10783 CHECK_RESULT(ctx, result);
10784 }
10785
10786 if(value->mask_generator != 0)
10787 {
10788 result = kmip_encode_enum(ctx, KMIP_TAG_MASK_GENERATOR, value->mask_generator);
10789 CHECK_RESULT(ctx, result);
10790 }
10791
10792 if(value->mask_generator_hashing_algorithm != 0)
10793 {
10794 result = kmip_encode_enum(ctx, KMIP_TAG_MASK_GENERATOR_HASHING_ALGORITHM, value->mask_generator_hashing_algorithm);
10795 CHECK_RESULT(ctx, result);
10796 }
10797
10798 if(value->p_source != NULL)
10799 {
10800 result = kmip_encode_byte_string(ctx, KMIP_TAG_P_SOURCE, value->p_source);
10801 CHECK_RESULT(ctx, result);
10802 }
10803
10804 if(value->trailer_field != KMIP_UNSET)
10805 {
10806 result = kmip_encode_integer(ctx, KMIP_TAG_TRAILER_FIELD, value->trailer_field);
10807 CHECK_RESULT(ctx, result);
10808 }
10809 }
10810
10811 uint8 *curr_index = ctx->index;
10812 ctx->index = length_index;
10813
10814 result = kmip_encode_length(ctx, curr_index - value_index);
10815 CHECK_RESULT(ctx, result);
10816
10817 ctx->index = curr_index;
10818
10819 return(KMIP_OK);
10820 }
10821
10822 int
10823 kmip_encode_encryption_key_information(KMIP *ctx, const EncryptionKeyInformation *value)
10824 {
10825 int result = 0;
10826 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ENCRYPTION_KEY_INFORMATION, KMIP_TYPE_STRUCTURE));
10827 CHECK_RESULT(ctx, result);
10828
10829 uint8 *length_index = ctx->index;
10830 uint8 *value_index = ctx->index += 4;
10831
10832 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
10833 CHECK_RESULT(ctx, result);
10834
10835 if(value->cryptographic_parameters != 0)
10836 {
10837 result = kmip_encode_cryptographic_parameters(ctx, value->cryptographic_parameters);
10838 CHECK_RESULT(ctx, result);
10839 }
10840
10841 uint8 *curr_index = ctx->index;
10842 ctx->index = length_index;
10843
10844 result = kmip_encode_length(ctx, curr_index - value_index);
10845 CHECK_RESULT(ctx, result);
10846
10847 ctx->index = curr_index;
10848
10849 return(KMIP_OK);
10850 }
10851
10852 int
10853 kmip_encode_mac_signature_key_information(KMIP *ctx, const MACSignatureKeyInformation *value)
10854 {
10855 int result = 0;
10856 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_MAC_SIGNATURE_KEY_INFORMATION, KMIP_TYPE_STRUCTURE));
10857 CHECK_RESULT(ctx, result);
10858
10859 uint8 *length_index = ctx->index;
10860 uint8 *value_index = ctx->index += 4;
10861
10862 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
10863 CHECK_RESULT(ctx, result);
10864
10865 if(value->cryptographic_parameters != 0)
10866 {
10867 result = kmip_encode_cryptographic_parameters(ctx, value->cryptographic_parameters);
10868 CHECK_RESULT(ctx, result);
10869 }
10870
10871 uint8 *curr_index = ctx->index;
10872 ctx->index = length_index;
10873
10874 result = kmip_encode_length(ctx, curr_index - value_index);
10875 CHECK_RESULT(ctx, result);
10876
10877 ctx->index = curr_index;
10878
10879 return(KMIP_OK);
10880 }
10881
10882 int
10883 kmip_encode_key_wrapping_data(KMIP *ctx, const KeyWrappingData *value)
10884 {
10885 int result = 0;
10886 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_KEY_WRAPPING_DATA, KMIP_TYPE_STRUCTURE));
10887 CHECK_RESULT(ctx, result);
10888
10889 uint8 *length_index = ctx->index;
10890 uint8 *value_index = ctx->index += 4;
10891
10892 result = kmip_encode_enum(ctx, KMIP_TAG_WRAPPING_METHOD, value->wrapping_method);
10893 CHECK_RESULT(ctx, result);
10894
10895 if(value->encryption_key_info != NULL)
10896 {
10897 result = kmip_encode_encryption_key_information(ctx, value->encryption_key_info);
10898 CHECK_RESULT(ctx, result);
10899 }
10900
10901 if(value->mac_signature_key_info != NULL)
10902 {
10903 result = kmip_encode_mac_signature_key_information(ctx, value->mac_signature_key_info);
10904 CHECK_RESULT(ctx, result);
10905 }
10906
10907 if(value->mac_signature != NULL)
10908 {
10909 result = kmip_encode_byte_string(ctx, KMIP_TAG_MAC_SIGNATURE, value->mac_signature);
10910 CHECK_RESULT(ctx, result);
10911 }
10912
10913 if(value->iv_counter_nonce != NULL)
10914 {
10915 result = kmip_encode_byte_string(ctx, KMIP_TAG_IV_COUNTER_NONCE, value->iv_counter_nonce);
10916 CHECK_RESULT(ctx, result);
10917 }
10918
10919 if(ctx->version >= KMIP_1_1)
10920 {
10921 result = kmip_encode_enum(ctx, KMIP_TAG_ENCODING_OPTION, value->encoding_option);
10922 CHECK_RESULT(ctx, result);
10923 }
10924
10925 uint8 *curr_index = ctx->index;
10926 ctx->index = length_index;
10927
10928 result = kmip_encode_length(ctx, curr_index - value_index);
10929 CHECK_RESULT(ctx, result);
10930
10931 ctx->index = curr_index;
10932
10933 return(KMIP_OK);
10934 }
10935
10936 int
10937 kmip_encode_transparent_symmetric_key(KMIP *ctx, const TransparentSymmetricKey *value)
10938 {
10939 int result = 0;
10940
10941 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_KEY_MATERIAL, KMIP_TYPE_STRUCTURE));
10942 CHECK_RESULT(ctx, result);
10943
10944 uint8 *length_index = ctx->index;
10945 uint8 *value_index = ctx->index += 4;
10946
10947 result = kmip_encode_byte_string(ctx, KMIP_TAG_KEY, value->key);
10948 CHECK_RESULT(ctx, result);
10949
10950 uint8 *curr_index = ctx->index;
10951 ctx->index = length_index;
10952
10953 result = kmip_encode_length(ctx, curr_index - value_index);
10954 CHECK_RESULT(ctx, result);
10955
10956 ctx->index = curr_index;
10957
10958 return(KMIP_OK);
10959 }
10960
10961 int
10962 kmip_encode_key_material(KMIP *ctx, enum key_format_type format, const void *value)
10963 {
10964 int result = 0;
10965
10966 switch(format)
10967 {
10968 case KMIP_KEYFORMAT_RAW:
10969 case KMIP_KEYFORMAT_OPAQUE:
10970 case KMIP_KEYFORMAT_PKCS1:
10971 case KMIP_KEYFORMAT_PKCS8:
10972 case KMIP_KEYFORMAT_X509:
10973 case KMIP_KEYFORMAT_EC_PRIVATE_KEY:
10974 result = kmip_encode_byte_string(ctx, KMIP_TAG_KEY_MATERIAL, (ByteString*)value);
10975 CHECK_RESULT(ctx, result);
10976 return(KMIP_OK);
10977 break;
10978
10979 default:
10980 break;
10981 };
10982
10983 switch(format)
10984 {
10985 case KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY:
10986 result = kmip_encode_transparent_symmetric_key(ctx, (TransparentSymmetricKey*)value);
10987 CHECK_RESULT(ctx, result);
10988 break;
10989
10990 /* TODO (ph) The rest require BigInteger support. */
10991
10992 case KMIP_KEYFORMAT_TRANS_DSA_PRIVATE_KEY:
10993 kmip_push_error_frame(ctx, __func__, __LINE__);
10994 return(KMIP_NOT_IMPLEMENTED);
10995 break;
10996
10997 case KMIP_KEYFORMAT_TRANS_DSA_PUBLIC_KEY:
10998 kmip_push_error_frame(ctx, __func__, __LINE__);
10999 return(KMIP_NOT_IMPLEMENTED);
11000 break;
11001
11002 case KMIP_KEYFORMAT_TRANS_RSA_PRIVATE_KEY:
11003 kmip_push_error_frame(ctx, __func__, __LINE__);
11004 return(KMIP_NOT_IMPLEMENTED);
11005 break;
11006
11007 case KMIP_KEYFORMAT_TRANS_RSA_PUBLIC_KEY:
11008 kmip_push_error_frame(ctx, __func__, __LINE__);
11009 return(KMIP_NOT_IMPLEMENTED);
11010 break;
11011
11012 case KMIP_KEYFORMAT_TRANS_DH_PRIVATE_KEY:
11013 kmip_push_error_frame(ctx, __func__, __LINE__);
11014 return(KMIP_NOT_IMPLEMENTED);
11015 break;
11016
11017 case KMIP_KEYFORMAT_TRANS_DH_PUBLIC_KEY:
11018 kmip_push_error_frame(ctx, __func__, __LINE__);
11019 return(KMIP_NOT_IMPLEMENTED);
11020 break;
11021
11022 case KMIP_KEYFORMAT_TRANS_ECDSA_PRIVATE_KEY:
11023 kmip_push_error_frame(ctx, __func__, __LINE__);
11024 return(KMIP_NOT_IMPLEMENTED);
11025 break;
11026
11027 case KMIP_KEYFORMAT_TRANS_ECDSA_PUBLIC_KEY:
11028 kmip_push_error_frame(ctx, __func__, __LINE__);
11029 return(KMIP_NOT_IMPLEMENTED);
11030 break;
11031
11032 case KMIP_KEYFORMAT_TRANS_ECDH_PRIVATE_KEY:
11033 kmip_push_error_frame(ctx, __func__, __LINE__);
11034 return(KMIP_NOT_IMPLEMENTED);
11035 break;
11036
11037 case KMIP_KEYFORMAT_TRANS_ECDH_PUBLIC_KEY:
11038 kmip_push_error_frame(ctx, __func__, __LINE__);
11039 return(KMIP_NOT_IMPLEMENTED);
11040 break;
11041
11042 case KMIP_KEYFORMAT_TRANS_ECMQV_PRIVATE_KEY:
11043 kmip_push_error_frame(ctx, __func__, __LINE__);
11044 return(KMIP_NOT_IMPLEMENTED);
11045 break;
11046
11047 case KMIP_KEYFORMAT_TRANS_ECMQV_PUBLIC_KEY:
11048 kmip_push_error_frame(ctx, __func__, __LINE__);
11049 return(KMIP_NOT_IMPLEMENTED);
11050 break;
11051
11052 default:
11053 kmip_push_error_frame(ctx, __func__, __LINE__);
11054 return(KMIP_NOT_IMPLEMENTED);
11055 break;
11056 };
11057
11058 return(KMIP_OK);
11059 }
11060
11061 int
11062 kmip_encode_key_value(KMIP *ctx, enum key_format_type format, const KeyValue *value)
11063 {
11064 int result = 0;
11065 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_KEY_VALUE, KMIP_TYPE_STRUCTURE));
11066 CHECK_RESULT(ctx, result);
11067
11068 uint8 *length_index = ctx->index;
11069 uint8 *value_index = ctx->index += 4;
11070
11071 result = kmip_encode_key_material(ctx, format, value->key_material);
11072 CHECK_RESULT(ctx, result);
11073
11074 for(size_t i = 0; i < value->attribute_count; i++)
11075 {
11076 result = kmip_encode_attribute(ctx, &value->attributes[i]);
11077 CHECK_RESULT(ctx, result);
11078 }
11079
11080 uint8 *curr_index = ctx->index;
11081 ctx->index = length_index;
11082
11083 result = kmip_encode_length(ctx, curr_index - value_index);
11084 CHECK_RESULT(ctx, result);
11085
11086 ctx->index = curr_index;
11087
11088 return(KMIP_OK);
11089 }
11090
11091 int
11092 kmip_encode_key_block(KMIP *ctx, const KeyBlock *value)
11093 {
11094 int result = 0;
11095 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_KEY_BLOCK, KMIP_TYPE_STRUCTURE));
11096 CHECK_RESULT(ctx, result);
11097
11098 uint8 *length_index = ctx->index;
11099 uint8 *value_index = ctx->index += 4;
11100
11101 result = kmip_encode_enum(ctx, KMIP_TAG_KEY_FORMAT_TYPE, value->key_format_type);
11102 CHECK_RESULT(ctx, result);
11103
11104 if(value->key_compression_type != 0)
11105 {
11106 result = kmip_encode_enum(ctx, KMIP_TAG_KEY_COMPRESSION_TYPE, value->key_compression_type);
11107 CHECK_RESULT(ctx, result);
11108 }
11109
11110 if(value->key_wrapping_data != NULL)
11111 {
11112 result = kmip_encode_byte_string(ctx, KMIP_TAG_KEY_VALUE, (ByteString*)value->key_value);
11113 }
11114 else
11115 {
11116 result = kmip_encode_key_value(ctx, value->key_format_type, (KeyValue*)value->key_value);
11117 }
11118 CHECK_RESULT(ctx, result);
11119
11120 if(value->cryptographic_algorithm != 0)
11121 {
11122 result = kmip_encode_enum(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM, value->cryptographic_algorithm);
11123 CHECK_RESULT(ctx, result);
11124 }
11125
11126 if(value->cryptographic_length != KMIP_UNSET)
11127 {
11128 result = kmip_encode_integer(ctx, KMIP_TAG_CRYPTOGRAPHIC_LENGTH, value->cryptographic_length);
11129 CHECK_RESULT(ctx, result);
11130 }
11131
11132 if(value->key_wrapping_data != NULL)
11133 {
11134 result = kmip_encode_key_wrapping_data(ctx, value->key_wrapping_data);
11135 CHECK_RESULT(ctx, result);
11136 }
11137
11138 uint8 *curr_index = ctx->index;
11139 ctx->index = length_index;
11140
11141 result = kmip_encode_length(ctx, curr_index - value_index);
11142 CHECK_RESULT(ctx, result);
11143
11144 ctx->index = curr_index;
11145
11146 return(KMIP_OK);
11147 }
11148
11149 int
11150 kmip_encode_symmetric_key(KMIP *ctx, const SymmetricKey *value)
11151 {
11152 int result = 0;
11153 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_SYMMETRIC_KEY, KMIP_TYPE_STRUCTURE));
11154 CHECK_RESULT(ctx, result);
11155
11156 uint8 *length_index = ctx->index;
11157 uint8 *value_index = ctx->index += 4;
11158
11159 result = kmip_encode_key_block(ctx, value->key_block);
11160 CHECK_RESULT(ctx, result);
11161
11162 uint8 *curr_index = ctx->index;
11163 ctx->index = length_index;
11164
11165 result = kmip_encode_length(ctx, curr_index - value_index);
11166 CHECK_RESULT(ctx, result);
11167
11168 ctx->index = curr_index;
11169
11170 return(KMIP_OK);
11171 }
11172
11173 int
11174 kmip_encode_public_key(KMIP *ctx, const PublicKey *value)
11175 {
11176 int result = 0;
11177 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_PUBLIC_KEY, KMIP_TYPE_STRUCTURE));
11178 CHECK_RESULT(ctx, result);
11179
11180 uint8 *length_index = ctx->index;
11181 uint8 *value_index = ctx->index += 4;
11182
11183 result = kmip_encode_key_block(ctx, value->key_block);
11184 CHECK_RESULT(ctx, result);
11185
11186 uint8 *curr_index = ctx->index;
11187 ctx->index = length_index;
11188
11189 result = kmip_encode_length(ctx, curr_index - value_index);
11190 CHECK_RESULT(ctx, result);
11191
11192 ctx->index = curr_index;
11193
11194 return(KMIP_OK);
11195 }
11196
11197 int
11198 kmip_encode_private_key(KMIP *ctx, const PrivateKey *value)
11199 {
11200 int result = 0;
11201 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_PRIVATE_KEY, KMIP_TYPE_STRUCTURE));
11202 CHECK_RESULT(ctx, result);
11203
11204 uint8 *length_index = ctx->index;
11205 uint8 *value_index = ctx->index += 4;
11206
11207 result = kmip_encode_key_block(ctx, value->key_block);
11208 CHECK_RESULT(ctx, result);
11209
11210 uint8 *curr_index = ctx->index;
11211 ctx->index = length_index;
11212
11213 result = kmip_encode_length(ctx, curr_index - value_index);
11214 CHECK_RESULT(ctx, result);
11215
11216 ctx->index = curr_index;
11217
11218 return(KMIP_OK);
11219 }
11220
11221 int
11222 kmip_encode_key_wrapping_specification(KMIP *ctx, const KeyWrappingSpecification *value)
11223 {
11224 int result = 0;
11225 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_KEY_WRAPPING_SPECIFICATION, KMIP_TYPE_STRUCTURE));
11226 CHECK_RESULT(ctx, result);
11227
11228 uint8 *length_index = ctx->index;
11229 uint8 *value_index = ctx->index += 4;
11230
11231 result = kmip_encode_enum(ctx, KMIP_TAG_WRAPPING_METHOD, value->wrapping_method);
11232 CHECK_RESULT(ctx, result);
11233
11234 if(value->encryption_key_info != NULL)
11235 {
11236 result = kmip_encode_encryption_key_information(ctx, value->encryption_key_info);
11237 CHECK_RESULT(ctx, result);
11238 }
11239
11240 if(value->mac_signature_key_info != NULL)
11241 {
11242 result = kmip_encode_mac_signature_key_information(ctx, value->mac_signature_key_info);
11243 CHECK_RESULT(ctx, result);
11244 }
11245
11246 for(size_t i = 0; i < value->attribute_name_count; i++)
11247 {
11248 result = kmip_encode_text_string(ctx, KMIP_TAG_ATTRIBUTE_NAME, &value->attribute_names[i]);
11249 CHECK_RESULT(ctx, result);
11250 }
11251
11252 if(ctx->version >= KMIP_1_1)
11253 {
11254 result = kmip_encode_enum(ctx, KMIP_TAG_ENCODING_OPTION, value->encoding_option);
11255 CHECK_RESULT(ctx, result);
11256 }
11257
11258 uint8 *curr_index = ctx->index;
11259 ctx->index = length_index;
11260
11261 result = kmip_encode_length(ctx, curr_index - value_index);
11262 CHECK_RESULT(ctx, result);
11263
11264 ctx->index = curr_index;
11265
11266 return(KMIP_OK);
11267 }
11268
11269 int
11270 kmip_encode_create_request_payload(KMIP *ctx, const CreateRequestPayload *value)
11271 {
11272 CHECK_ENCODE_ARGS(ctx, value);
11273
11274 int result = 0;
11275 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE));
11276 CHECK_RESULT(ctx, result);
11277
11278 uint8 *length_index = ctx->index;
11279 uint8 *value_index = ctx->index += 4;
11280
11281 result = kmip_encode_enum(ctx, KMIP_TAG_OBJECT_TYPE, value->object_type);
11282 CHECK_RESULT(ctx, result);
11283
11284 if(ctx->version < KMIP_2_0)
11285 {
11286 result = kmip_encode_template_attribute(ctx, value->template_attribute);
11287 CHECK_RESULT(ctx, result);
11288 }
11289 else
11290 {
11291 if(value->attributes)
11292 {
11293 result = kmip_encode_attributes(ctx, value->attributes);
11294 CHECK_RESULT(ctx, result);
11295 }
11296 else if(value->template_attribute)
11297 {
11298 Attributes *attributes = ctx->calloc_func(ctx->state, 1, sizeof(Attributes));
11299 LinkedList *list = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
11300 attributes->attribute_list = list;
11301 for(size_t i = 0; i < value->template_attribute->attribute_count; i++)
11302 {
11303 LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
11304 item->data = kmip_deep_copy_attribute(ctx, &value->template_attribute->attributes[i]);
11305 kmip_linked_list_enqueue(list, item);
11306 }
11307
11308 result = kmip_encode_attributes(ctx, attributes);
11309
11310 kmip_free_attributes(ctx, attributes);
11311 ctx->free_func(ctx->state, attributes);
11312
11313 CHECK_RESULT(ctx, result);
11314 }
11315
11316 if(value->protection_storage_masks != NULL)
11317 {
11318 result = kmip_encode_protection_storage_masks(ctx, value->protection_storage_masks);
11319 CHECK_RESULT(ctx, result);
11320 }
11321 }
11322
11323 uint8 *curr_index = ctx->index;
11324 ctx->index = length_index;
11325
11326 result = kmip_encode_length(ctx, curr_index - value_index);
11327 CHECK_RESULT(ctx, result);
11328
11329 ctx->index = curr_index;
11330
11331 return(KMIP_OK);
11332 }
11333
11334 int
11335 kmip_encode_create_response_payload(KMIP *ctx, const CreateResponsePayload *value)
11336 {
11337 CHECK_ENCODE_ARGS(ctx, value);
11338
11339 int result = 0;
11340 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE));
11341 CHECK_RESULT(ctx, result);
11342
11343 uint8 *length_index = ctx->index;
11344 uint8 *value_index = ctx->index += 4;
11345
11346 result = kmip_encode_enum(ctx, KMIP_TAG_OBJECT_TYPE, value->object_type);
11347 CHECK_RESULT(ctx, result);
11348
11349 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
11350 CHECK_RESULT(ctx, result);
11351
11352 if(ctx->version < KMIP_2_0)
11353 {
11354 if(value->template_attribute != NULL)
11355 {
11356 result = kmip_encode_template_attribute(ctx, value->template_attribute);
11357 CHECK_RESULT(ctx, result);
11358 }
11359 }
11360
11361 uint8 *curr_index = ctx->index;
11362 ctx->index = length_index;
11363
11364 result = kmip_encode_length(ctx, curr_index - value_index);
11365 CHECK_RESULT(ctx, result);
11366
11367 ctx->index = curr_index;
11368
11369 return(KMIP_OK);
11370 }
11371
11372 int
11373 kmip_encode_register_request_payload(KMIP *ctx, const RegisterRequestPayload *value)
11374 {
11375 CHECK_ENCODE_ARGS(ctx, value);
11376
11377 int result = 0;
11378 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE));
11379 CHECK_RESULT(ctx, result);
11380
11381 uint8 *length_index = ctx->index;
11382 uint8 *value_index = ctx->index += 4;
11383
11384 result = kmip_encode_enum(ctx, KMIP_TAG_OBJECT_TYPE, value->object_type);
11385 CHECK_RESULT(ctx, result);
11386
11387 if(ctx->version < KMIP_2_0)
11388 {
11389 result = kmip_encode_template_attribute(ctx, value->template_attribute);
11390 CHECK_RESULT(ctx, result);
11391 }
11392 else
11393 {
11394 if(value->attributes)
11395 {
11396 result = kmip_encode_attributes(ctx, value->attributes);
11397 CHECK_RESULT(ctx, result);
11398 }
11399 else if(value->template_attribute)
11400 {
11401 Attributes *attributes = ctx->calloc_func(ctx->state, 1, sizeof(Attributes));
11402 LinkedList *list = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
11403 attributes->attribute_list = list;
11404 for(size_t i = 0; i < value->template_attribute->attribute_count; i++)
11405 {
11406 LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
11407 item->data = kmip_deep_copy_attribute(ctx, &value->template_attribute->attributes[i]);
11408 kmip_linked_list_enqueue(list, item);
11409 }
11410
11411 result = kmip_encode_attributes(ctx, attributes);
11412
11413 kmip_free_attributes(ctx, attributes);
11414 ctx->free_func(ctx->state, attributes);
11415
11416 CHECK_RESULT(ctx, result);
11417 }
11418
11419 if(value->protection_storage_masks != NULL)
11420 {
11421 result = kmip_encode_protection_storage_masks(ctx, value->protection_storage_masks);
11422 CHECK_RESULT(ctx, result);
11423 }
11424 }
11425
11426 // TODO: this currently onlyhandles symmetric keys, but in theory the protocol also supports other types
11427 result = kmip_encode_symmetric_key(ctx, &value->object);
11428 CHECK_RESULT(ctx, result);
11429
11430 uint8 *curr_index = ctx->index;
11431 ctx->index = length_index;
11432
11433 result = kmip_encode_length(ctx, curr_index - value_index);
11434 CHECK_RESULT(ctx, result);
11435
11436 ctx->index = curr_index;
11437
11438 return(KMIP_OK);
11439 }
11440
11441 int
11442 kmip_encode_register_response_payload(KMIP *ctx, const RegisterResponsePayload *value)
11443 {
11444 CHECK_ENCODE_ARGS(ctx, value);
11445
11446 int result = 0;
11447 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE));
11448 CHECK_RESULT(ctx, result);
11449
11450 uint8 *length_index = ctx->index;
11451 uint8 *value_index = ctx->index += 4;
11452
11453 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
11454 CHECK_RESULT(ctx, result);
11455
11456 if(ctx->version < KMIP_2_0)
11457 {
11458 if(value->template_attribute != NULL)
11459 {
11460 result = kmip_encode_template_attribute(ctx, value->template_attribute);
11461 CHECK_RESULT(ctx, result);
11462 }
11463 }
11464
11465 uint8 *curr_index = ctx->index;
11466 ctx->index = length_index;
11467
11468 result = kmip_encode_length(ctx, curr_index - value_index);
11469 CHECK_RESULT(ctx, result);
11470
11471 ctx->index = curr_index;
11472
11473 return(KMIP_OK);
11474 }
11475
11476 int
11477 kmip_encode_get_request_payload(KMIP *ctx, const GetRequestPayload *value)
11478 {
11479 int result = 0;
11480 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE));
11481 CHECK_RESULT(ctx, result);
11482
11483 uint8 *length_index = ctx->index;
11484 uint8 *value_index = ctx->index += 4;
11485
11486 if(value->unique_identifier != NULL)
11487 {
11488 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
11489 CHECK_RESULT(ctx, result);
11490 }
11491
11492 if(value->key_format_type != 0)
11493 {
11494 result = kmip_encode_enum(ctx, KMIP_TAG_KEY_FORMAT_TYPE, value->key_format_type);
11495 CHECK_RESULT(ctx, result);
11496 }
11497
11498 if(ctx->version >= KMIP_1_4)
11499 {
11500 if(value->key_wrap_type != 0)
11501 {
11502 result = kmip_encode_enum(ctx, KMIP_TAG_KEY_WRAP_TYPE, value->key_wrap_type);
11503 CHECK_RESULT(ctx, result);
11504 }
11505 }
11506
11507 if(value->key_compression_type != 0)
11508 {
11509 result = kmip_encode_enum(ctx, KMIP_TAG_KEY_COMPRESSION_TYPE, value->key_compression_type);
11510 CHECK_RESULT(ctx, result);
11511 }
11512
11513 if(value->key_wrapping_spec != NULL)
11514 {
11515 result = kmip_encode_key_wrapping_specification(ctx, value->key_wrapping_spec);
11516 CHECK_RESULT(ctx, result);
11517 }
11518
11519 uint8 *curr_index = ctx->index;
11520 ctx->index = length_index;
11521
11522 result = kmip_encode_length(ctx, curr_index - value_index);
11523 CHECK_RESULT(ctx, result);
11524
11525 ctx->index = curr_index;
11526
11527 return(KMIP_OK);
11528 }
11529
11530 int
11531 kmip_encode_get_response_payload(KMIP *ctx, const GetResponsePayload *value)
11532 {
11533 int result = 0;
11534 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE));
11535 CHECK_RESULT(ctx, result);
11536
11537 uint8 *length_index = ctx->index;
11538 uint8 *value_index = ctx->index += 4;
11539
11540 result = kmip_encode_enum(ctx, KMIP_TAG_OBJECT_TYPE, value->object_type);
11541 CHECK_RESULT(ctx, result);
11542
11543 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
11544 CHECK_RESULT(ctx, result);
11545
11546 switch(value->object_type)
11547 {
11548 case KMIP_OBJTYPE_SYMMETRIC_KEY:
11549 result = kmip_encode_symmetric_key(ctx, (const SymmetricKey*)value->object);
11550 CHECK_RESULT(ctx, result);
11551 break;
11552
11553 case KMIP_OBJTYPE_PUBLIC_KEY:
11554 result = kmip_encode_public_key(ctx, (const PublicKey*)value->object);
11555 CHECK_RESULT(ctx, result);
11556 break;
11557
11558 case KMIP_OBJTYPE_PRIVATE_KEY:
11559 result = kmip_encode_private_key(ctx, (const PrivateKey*)value->object);
11560 CHECK_RESULT(ctx, result);
11561 break;
11562
11563 default:
11564 kmip_push_error_frame(ctx, __func__, __LINE__);
11565 return(KMIP_NOT_IMPLEMENTED);
11566 break;
11567 };
11568
11569 uint8 *curr_index = ctx->index;
11570 ctx->index = length_index;
11571
11572 result = kmip_encode_length(ctx, curr_index - value_index);
11573 CHECK_RESULT(ctx, result);
11574
11575 ctx->index = curr_index;
11576
11577 return(KMIP_OK);
11578 }
11579
11580 int
11581 kmip_encode_get_attribute_request_payload(KMIP *ctx, const GetAttributeRequestPayload *value)
11582 {
11583 int result = 0;
11584 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE));
11585 CHECK_RESULT(ctx, result);
11586
11587 uint8 *length_index = ctx->index;
11588 uint8 *value_index = ctx->index += 4;
11589
11590 if(value->unique_identifier != NULL)
11591 {
11592 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
11593 CHECK_RESULT(ctx, result);
11594 }
11595
11596 if(value->attribute_name != NULL)
11597 {
11598 result = kmip_encode_text_string(ctx, KMIP_TAG_ATTRIBUTE_NAME, value->attribute_name);
11599 CHECK_RESULT(ctx, result);
11600 }
11601
11602 uint8 *curr_index = ctx->index;
11603 ctx->index = length_index;
11604
11605 result = kmip_encode_length(ctx, curr_index - value_index);
11606 CHECK_RESULT(ctx, result);
11607
11608 ctx->index = curr_index;
11609
11610 return(KMIP_OK);
11611 }
11612
11613 int
11614 kmip_encode_get_attribute_response_payload(KMIP *ctx, const GetAttributeResponsePayload *value)
11615 {
11616 int result = 0;
11617 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE));
11618 CHECK_RESULT(ctx, result);
11619
11620 uint8 *length_index = ctx->index;
11621 uint8 *value_index = ctx->index += 4;
11622
11623 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
11624 CHECK_RESULT(ctx, result);
11625
11626 result = kmip_decode_attribute(ctx, value->attribute);
11627 CHECK_RESULT(ctx, result);
11628
11629 uint8 *curr_index = ctx->index;
11630 ctx->index = length_index;
11631
11632 result = kmip_encode_length(ctx, curr_index - value_index);
11633 CHECK_RESULT(ctx, result);
11634
11635 ctx->index = curr_index;
11636
11637 return(KMIP_OK);
11638 }
11639
11640 int
11641 kmip_encode_destroy_request_payload(KMIP *ctx, const DestroyRequestPayload *value)
11642 {
11643 int result = 0;
11644 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE));
11645 CHECK_RESULT(ctx, result);
11646
11647 uint8 *length_index = ctx->index;
11648 uint8 *value_index = ctx->index += 4;
11649
11650 if(value->unique_identifier != NULL)
11651 {
11652 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
11653 CHECK_RESULT(ctx, result);
11654 }
11655
11656 uint8 *curr_index = ctx->index;
11657 ctx->index = length_index;
11658
11659 result = kmip_encode_length(ctx, curr_index - value_index);
11660 CHECK_RESULT(ctx, result);
11661
11662 ctx->index = curr_index;
11663
11664 return(KMIP_OK);
11665 }
11666
11667 int
11668 kmip_encode_destroy_response_payload(KMIP *ctx, const DestroyResponsePayload *value)
11669 {
11670 int result = 0;
11671 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE));
11672 CHECK_RESULT(ctx, result);
11673
11674 uint8 *length_index = ctx->index;
11675 uint8 *value_index = ctx->index += 4;
11676
11677 result = kmip_encode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
11678 CHECK_RESULT(ctx, result);
11679
11680 uint8 *curr_index = ctx->index;
11681 ctx->index = length_index;
11682
11683 result = kmip_encode_length(ctx, curr_index - value_index);
11684 CHECK_RESULT(ctx, result);
11685
11686 ctx->index = curr_index;
11687
11688 return(KMIP_OK);
11689 }
11690
11691 int
11692 kmip_encode_nonce(KMIP *ctx, const Nonce *value)
11693 {
11694 int result = 0;
11695 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_NONCE, KMIP_TYPE_STRUCTURE));
11696 CHECK_RESULT(ctx, result);
11697
11698 uint8 *length_index = ctx->index;
11699 uint8 *value_index = ctx->index += 4;
11700
11701 result = kmip_encode_byte_string(ctx, KMIP_TAG_NONCE_ID, value->nonce_id);
11702 CHECK_RESULT(ctx, result);
11703
11704 result = kmip_encode_byte_string(ctx, KMIP_TAG_NONCE_VALUE, value->nonce_value);
11705 CHECK_RESULT(ctx, result);
11706
11707 uint8 *curr_index = ctx->index;
11708 ctx->index = length_index;
11709
11710 result = kmip_encode_length(ctx, curr_index - value_index);
11711 CHECK_RESULT(ctx, result);
11712
11713 ctx->index = curr_index;
11714
11715 return(KMIP_OK);
11716 }
11717
11718 int
11719 kmip_encode_username_password_credential(KMIP *ctx, const UsernamePasswordCredential *value)
11720 {
11721 int result = 0;
11722 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_CREDENTIAL_VALUE, KMIP_TYPE_STRUCTURE));
11723 CHECK_RESULT(ctx, result);
11724
11725 uint8 *length_index = ctx->index;
11726 uint8 *value_index = ctx->index += 4;
11727
11728 result = kmip_encode_text_string(ctx, KMIP_TAG_USERNAME, value->username);
11729 CHECK_RESULT(ctx, result);
11730
11731 if(value->password != NULL)
11732 {
11733 result = kmip_encode_text_string(ctx, KMIP_TAG_PASSWORD, value->password);
11734 CHECK_RESULT(ctx, result);
11735 }
11736
11737 uint8 *curr_index = ctx->index;
11738 ctx->index = length_index;
11739
11740 result = kmip_encode_length(ctx, curr_index - value_index);
11741 CHECK_RESULT(ctx, result);
11742
11743 ctx->index = curr_index;
11744
11745 return(KMIP_OK);
11746 }
11747
11748 int
11749 kmip_encode_device_credential(KMIP *ctx, const DeviceCredential *value)
11750 {
11751 int result = 0;
11752 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_CREDENTIAL_VALUE, KMIP_TYPE_STRUCTURE));
11753 CHECK_RESULT(ctx, result);
11754
11755 uint8 *length_index = ctx->index;
11756 uint8 *value_index = ctx->index += 4;
11757
11758 if(value->device_serial_number != NULL)
11759 {
11760 result = kmip_encode_text_string(ctx, KMIP_TAG_DEVICE_SERIAL_NUMBER, value->device_serial_number);
11761 CHECK_RESULT(ctx, result);
11762 }
11763
11764 if(value->password != NULL)
11765 {
11766 result = kmip_encode_text_string(ctx, KMIP_TAG_PASSWORD, value->password);
11767 CHECK_RESULT(ctx, result);
11768 }
11769
11770 if(value->device_identifier != NULL)
11771 {
11772 result = kmip_encode_text_string(ctx, KMIP_TAG_DEVICE_IDENTIFIER, value->device_identifier);
11773 CHECK_RESULT(ctx, result);
11774 }
11775
11776 if(value->network_identifier != NULL)
11777 {
11778 result = kmip_encode_text_string(ctx, KMIP_TAG_NETWORK_IDENTIFIER, value->network_identifier);
11779 CHECK_RESULT(ctx, result);
11780 }
11781
11782 if(value->machine_identifier != NULL)
11783 {
11784 result = kmip_encode_text_string(ctx, KMIP_TAG_MACHINE_IDENTIFIER, value->machine_identifier);
11785 CHECK_RESULT(ctx, result);
11786 }
11787
11788 if(value->media_identifier != NULL)
11789 {
11790 result = kmip_encode_text_string(ctx, KMIP_TAG_MEDIA_IDENTIFIER, value->media_identifier);
11791 CHECK_RESULT(ctx, result);
11792 }
11793
11794 uint8 *curr_index = ctx->index;
11795 ctx->index = length_index;
11796
11797 result = kmip_encode_length(ctx, curr_index - value_index);
11798 CHECK_RESULT(ctx, result);
11799
11800 ctx->index = curr_index;
11801
11802 return(KMIP_OK);
11803 }
11804
11805 int
11806 kmip_encode_attestation_credential(KMIP *ctx, const AttestationCredential *value)
11807 {
11808 int result = 0;
11809 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_CREDENTIAL_VALUE, KMIP_TYPE_STRUCTURE));
11810 CHECK_RESULT(ctx, result);
11811
11812 uint8 *length_index = ctx->index;
11813 uint8 *value_index = ctx->index += 4;
11814
11815 result = kmip_encode_nonce(ctx, value->nonce);
11816 CHECK_RESULT(ctx, result);
11817
11818 result = kmip_encode_enum(ctx, KMIP_TAG_ATTESTATION_TYPE, value->attestation_type);
11819 CHECK_RESULT(ctx, result);
11820
11821 if(value->attestation_measurement != NULL)
11822 {
11823 result = kmip_encode_byte_string(ctx, KMIP_TAG_ATTESTATION_MEASUREMENT, value->attestation_measurement);
11824 CHECK_RESULT(ctx, result);
11825 }
11826
11827 if(value->attestation_assertion != NULL)
11828 {
11829 result = kmip_encode_byte_string(ctx, KMIP_TAG_ATTESTATION_ASSERTION, value->attestation_assertion);
11830 CHECK_RESULT(ctx, result);
11831 }
11832
11833 uint8 *curr_index = ctx->index;
11834 ctx->index = length_index;
11835
11836 result = kmip_encode_length(ctx, curr_index - value_index);
11837 CHECK_RESULT(ctx, result);
11838
11839 ctx->index = curr_index;
11840
11841 return(KMIP_OK);
11842 }
11843
11844 int
11845 kmip_encode_credential_value(KMIP *ctx, enum credential_type type, void *value)
11846 {
11847 int result = 0;
11848
11849 switch(type)
11850 {
11851 case KMIP_CRED_USERNAME_AND_PASSWORD:
11852 result = kmip_encode_username_password_credential(ctx, (UsernamePasswordCredential*)value);
11853 break;
11854
11855 case KMIP_CRED_DEVICE:
11856 result = kmip_encode_device_credential(ctx, (DeviceCredential*)value);
11857 break;
11858
11859 case KMIP_CRED_ATTESTATION:
11860 result = kmip_encode_attestation_credential(ctx, (AttestationCredential*)value);
11861 break;
11862
11863 default:
11864 kmip_push_error_frame(ctx, __func__, __LINE__);
11865 return(KMIP_NOT_IMPLEMENTED);
11866 break;
11867 }
11868 CHECK_RESULT(ctx, result);
11869
11870 return(KMIP_OK);
11871 }
11872
11873 int
11874 kmip_encode_credential(KMIP *ctx, const Credential *value)
11875 {
11876 int result = 0;
11877 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_CREDENTIAL, KMIP_TYPE_STRUCTURE));
11878 CHECK_RESULT(ctx, result);
11879
11880 uint8 *length_index = ctx->index;
11881 uint8 *value_index = ctx->index += 4;
11882
11883 result = kmip_encode_enum(ctx, KMIP_TAG_CREDENTIAL_TYPE, value->credential_type);
11884 CHECK_RESULT(ctx, result);
11885
11886 result = kmip_encode_credential_value(ctx, value->credential_type, value->credential_value);
11887 CHECK_RESULT(ctx, result);
11888
11889 uint8 *curr_index = ctx->index;
11890 ctx->index = length_index;
11891
11892 result = kmip_encode_length(ctx, curr_index - value_index);
11893 CHECK_RESULT(ctx, result);
11894
11895 ctx->index = curr_index;
11896
11897 return(KMIP_OK);
11898 }
11899
11900 int
11901 kmip_encode_authentication(KMIP *ctx, const Authentication *value)
11902 {
11903 int result = 0;
11904 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_AUTHENTICATION, KMIP_TYPE_STRUCTURE));
11905 CHECK_RESULT(ctx, result);
11906
11907 uint8 *length_index = ctx->index;
11908 uint8 *value_index = ctx->index += 4;
11909
11910 result = kmip_encode_credential(ctx, value->credential);
11911 CHECK_RESULT(ctx, result);
11912
11913 uint8 *curr_index = ctx->index;
11914 ctx->index = length_index;
11915
11916 result = kmip_encode_length(ctx, curr_index - value_index);
11917 CHECK_RESULT(ctx, result);
11918
11919 ctx->index = curr_index;
11920
11921 return(KMIP_OK);
11922 }
11923
11924 int
11925 kmip_encode_request_header(KMIP *ctx, const RequestHeader *value)
11926 {
11927 int result = 0;
11928 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_REQUEST_HEADER, KMIP_TYPE_STRUCTURE));
11929 CHECK_RESULT(ctx, result);
11930
11931 uint8 *length_index = ctx->index;
11932 uint8 *value_index = ctx->index += 4;
11933
11934 result = kmip_encode_protocol_version(ctx, value->protocol_version);
11935 CHECK_RESULT(ctx, result);
11936
11937 /* HERE (ph) Stopped working here after bug with 0 vs KMIP_UNSET */
11938 if(value->maximum_response_size != KMIP_UNSET)
11939 {
11940 result = kmip_encode_integer(ctx, KMIP_TAG_MAXIMUM_RESPONSE_SIZE, value->maximum_response_size);
11941 CHECK_RESULT(ctx, result);
11942 }
11943
11944 if(ctx->version >= KMIP_1_4)
11945 {
11946 if(value->client_correlation_value != NULL)
11947 {
11948 result = kmip_encode_text_string(ctx, KMIP_TAG_CLIENT_CORRELATION_VALUE, value->client_correlation_value);
11949 CHECK_RESULT(ctx, result);
11950 }
11951
11952 if(value->server_correlation_value != NULL)
11953 {
11954 result = kmip_encode_text_string(ctx, KMIP_TAG_SERVER_CORRELATION_VALUE, value->server_correlation_value);
11955 CHECK_RESULT(ctx, result);
11956 }
11957 }
11958
11959 if(value->asynchronous_indicator != KMIP_UNSET)
11960 {
11961 result = kmip_encode_bool(ctx, KMIP_TAG_ASYNCHRONOUS_INDICATOR, value->asynchronous_indicator);
11962 CHECK_RESULT(ctx, result);
11963 }
11964
11965 if(ctx->version >= KMIP_1_2)
11966 {
11967 if(value->attestation_capable_indicator != KMIP_UNSET)
11968 {
11969 result = kmip_encode_bool(ctx, KMIP_TAG_ATTESTATION_CAPABLE_INDICATOR, value->attestation_capable_indicator);
11970 CHECK_RESULT(ctx, result);
11971 }
11972
11973 for(size_t i = 0; i < value->attestation_type_count; i++)
11974 {
11975 result = kmip_encode_enum(ctx, KMIP_TAG_ATTESTATION_TYPE, value->attestation_types[i]);
11976 CHECK_RESULT(ctx, result);
11977 }
11978 }
11979
11980 if(value->authentication != NULL)
11981 {
11982 result = kmip_encode_authentication(ctx, value->authentication);
11983 CHECK_RESULT(ctx, result);
11984 }
11985
11986 if(value->batch_error_continuation_option != 0)
11987 {
11988 result = kmip_encode_enum(ctx, KMIP_TAG_BATCH_ERROR_CONTINUATION_OPTION, value->batch_error_continuation_option);
11989 CHECK_RESULT(ctx, result);
11990 }
11991
11992 if(value->batch_order_option != KMIP_UNSET)
11993 {
11994 result = kmip_encode_bool(ctx, KMIP_TAG_BATCH_ORDER_OPTION, value->batch_order_option);
11995 CHECK_RESULT(ctx, result);
11996 }
11997
11998 if(value->time_stamp != 0)
11999 {
12000 result = kmip_encode_date_time(ctx, KMIP_TAG_TIME_STAMP, value->time_stamp);
12001 CHECK_RESULT(ctx, result);
12002 }
12003
12004 result = kmip_encode_integer(ctx, KMIP_TAG_BATCH_COUNT, value->batch_count);
12005 CHECK_RESULT(ctx, result);
12006
12007 uint8 *curr_index = ctx->index;
12008 ctx->index = length_index;
12009
12010 result = kmip_encode_length(ctx, curr_index - value_index);
12011 CHECK_RESULT(ctx, result);
12012
12013 ctx->index = curr_index;
12014
12015 return(KMIP_OK);
12016 }
12017
12018 int
12019 kmip_encode_response_header(KMIP *ctx, const ResponseHeader *value)
12020 {
12021 int result = 0;
12022 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_RESPONSE_HEADER, KMIP_TYPE_STRUCTURE));
12023 CHECK_RESULT(ctx, result);
12024
12025 uint8 *length_index = ctx->index;
12026 uint8 *value_index = ctx->index += 4;
12027
12028 result = kmip_encode_protocol_version(ctx, value->protocol_version);
12029 CHECK_RESULT(ctx, result);
12030
12031 result = kmip_encode_date_time(ctx, KMIP_TAG_TIME_STAMP, value->time_stamp);
12032 CHECK_RESULT(ctx, result);
12033
12034 if(ctx->version >= KMIP_1_2)
12035 {
12036 if(value->nonce != NULL)
12037 {
12038 result = kmip_encode_nonce(ctx, value->nonce);
12039 CHECK_RESULT(ctx, result);
12040 }
12041
12042 if(ctx->version >= KMIP_2_0)
12043 {
12044 if(value->server_hashed_password != NULL)
12045 {
12046 result = kmip_encode_byte_string(ctx, KMIP_TAG_SERVER_HASHED_PASSWORD, value->server_hashed_password);
12047 CHECK_RESULT(ctx, result);
12048 }
12049 }
12050
12051 for(size_t i = 0; i < value->attestation_type_count; i++)
12052 {
12053 result = kmip_encode_enum(ctx, KMIP_TAG_ATTESTATION_TYPE, value->attestation_types[i]);
12054 CHECK_RESULT(ctx, result);
12055 }
12056 }
12057
12058 if(ctx->version >= KMIP_1_4)
12059 {
12060 if(value->client_correlation_value != NULL)
12061 {
12062 result = kmip_encode_text_string(ctx, KMIP_TAG_CLIENT_CORRELATION_VALUE, value->client_correlation_value);
12063 CHECK_RESULT(ctx, result);
12064 }
12065
12066 if(value->server_correlation_value != NULL)
12067 {
12068 result = kmip_encode_text_string(ctx, KMIP_TAG_SERVER_CORRELATION_VALUE, value->server_correlation_value);
12069 CHECK_RESULT(ctx, result);
12070 }
12071 }
12072
12073 result = kmip_encode_integer(ctx, KMIP_TAG_BATCH_COUNT, value->batch_count);
12074 CHECK_RESULT(ctx, result);
12075
12076 uint8 *curr_index = ctx->index;
12077 ctx->index = length_index;
12078
12079 result = kmip_encode_length(ctx, curr_index - value_index);
12080 CHECK_RESULT(ctx, result);
12081
12082 ctx->index = curr_index;
12083
12084 return(KMIP_OK);
12085 }
12086
12087 int
12088 kmip_encode_request_batch_item(KMIP *ctx, const RequestBatchItem *value)
12089 {
12090 CHECK_ENCODE_ARGS(ctx, value);
12091
12092 int result = 0;
12093 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_BATCH_ITEM, KMIP_TYPE_STRUCTURE));
12094 CHECK_RESULT(ctx, result);
12095
12096 uint8 *length_index = ctx->index;
12097 uint8 *value_index = ctx->index += 4;
12098
12099 result = kmip_encode_enum(ctx, KMIP_TAG_OPERATION, value->operation);
12100 CHECK_RESULT(ctx, result);
12101
12102 if(ctx->version >= KMIP_2_0)
12103 {
12104 if(value->ephemeral != KMIP_UNSET)
12105 {
12106 result=kmip_encode_bool(ctx, KMIP_TAG_EPHEMERAL, value->ephemeral);
12107 CHECK_RESULT(ctx, result);
12108 }
12109 }
12110
12111 if(value->unique_batch_item_id != NULL)
12112 {
12113 result = kmip_encode_byte_string(ctx, KMIP_TAG_UNIQUE_BATCH_ITEM_ID, value->unique_batch_item_id);
12114 CHECK_RESULT(ctx, result);
12115 }
12116
12117 switch(value->operation)
12118 {
12119 case KMIP_OP_CREATE:
12120 result = kmip_encode_create_request_payload(ctx, (CreateRequestPayload*)value->request_payload);
12121 break;
12122
12123 case KMIP_OP_REGISTER:
12124 result = kmip_encode_register_request_payload(ctx, (RegisterRequestPayload*)value->request_payload);
12125 break;
12126
12127 case KMIP_OP_GET:
12128 result = kmip_encode_get_request_payload(ctx, (GetRequestPayload*)value->request_payload);
12129 break;
12130
12131 case KMIP_OP_GET_ATTRIBUTES:
12132 result = kmip_encode_get_attribute_request_payload(ctx, (GetAttributeRequestPayload*)value->request_payload);
12133 break;
12134
12135 case KMIP_OP_DESTROY:
12136 result = kmip_encode_destroy_request_payload(ctx, (DestroyRequestPayload*)value->request_payload);
12137 break;
12138
12139 case KMIP_OP_QUERY:
12140 result = kmip_encode_query_request_payload(ctx, (QueryRequestPayload*)value->request_payload);
12141 break;
12142
12143 case KMIP_OP_LOCATE:
12144 result = kmip_encode_locate_request_payload(ctx, (LocateRequestPayload*)value->request_payload);
12145 break;
12146
12147 default:
12148 kmip_push_error_frame(ctx, __func__, __LINE__);
12149 return(KMIP_NOT_IMPLEMENTED);
12150 break;
12151 };
12152 CHECK_RESULT(ctx, result);
12153
12154 uint8 *curr_index = ctx->index;
12155 ctx->index = length_index;
12156
12157 result = kmip_encode_length(ctx, curr_index - value_index);
12158 CHECK_RESULT(ctx, result);
12159
12160 ctx->index = curr_index;
12161
12162 return(KMIP_OK);
12163 }
12164
12165 int
12166 kmip_encode_response_batch_item(KMIP *ctx, const ResponseBatchItem *value)
12167 {
12168 int result = 0;
12169 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_BATCH_ITEM, KMIP_TYPE_STRUCTURE));
12170 CHECK_RESULT(ctx, result);
12171
12172 uint8 *length_index = ctx->index;
12173 uint8 *value_index = ctx->index += 4;
12174
12175 result = kmip_encode_enum(ctx, KMIP_TAG_OPERATION, value->operation);
12176 CHECK_RESULT(ctx, result);
12177
12178 if(value->unique_batch_item_id != NULL)
12179 {
12180 result = kmip_encode_byte_string(ctx, KMIP_TAG_UNIQUE_BATCH_ITEM_ID, value->unique_batch_item_id);
12181 CHECK_RESULT(ctx, result);
12182 }
12183
12184 result = kmip_encode_enum(ctx, KMIP_TAG_RESULT_STATUS, value->result_status);
12185 CHECK_RESULT(ctx, result);
12186
12187 if(value->result_reason != 0)
12188 {
12189 result = kmip_encode_enum(ctx, KMIP_TAG_RESULT_REASON, value->result_reason);
12190 CHECK_RESULT(ctx, result);
12191 }
12192
12193 if(value->result_message != NULL)
12194 {
12195 result = kmip_encode_text_string(ctx, KMIP_TAG_RESULT_MESSAGE, value->result_message);
12196 CHECK_RESULT(ctx, result);
12197 }
12198
12199 if(value->asynchronous_correlation_value != NULL)
12200 {
12201 result = kmip_encode_byte_string(ctx, KMIP_TAG_ASYNCHRONOUS_CORRELATION_VALUE, value->asynchronous_correlation_value);
12202 CHECK_RESULT(ctx, result);
12203 }
12204
12205 switch(value->operation)
12206 {
12207 case KMIP_OP_CREATE:
12208 result = kmip_encode_create_response_payload(ctx, (CreateResponsePayload*)value->response_payload);
12209 break;
12210
12211 case KMIP_OP_REGISTER:
12212 result = kmip_encode_register_response_payload(ctx, (RegisterResponsePayload*)value->response_payload);
12213 break;
12214
12215 case KMIP_OP_GET_ATTRIBUTES:
12216 result = kmip_encode_get_attribute_response_payload(ctx, (GetAttributeResponsePayload*)value->response_payload);
12217 break;
12218
12219 case KMIP_OP_DESTROY:
12220 result = kmip_encode_destroy_response_payload(ctx, (DestroyResponsePayload*)value->response_payload);
12221 break;
12222
12223 case KMIP_OP_QUERY:
12224 result = kmip_encode_query_response_payload(ctx, (QueryResponsePayload*)value->response_payload);
12225 break;
12226
12227 case KMIP_OP_LOCATE:
12228 result = kmip_encode_locate_response_payload(ctx, (LocateResponsePayload*)value->response_payload);
12229 break;
12230
12231 default:
12232 kmip_push_error_frame(ctx, __func__, __LINE__);
12233 return(KMIP_NOT_IMPLEMENTED);
12234 break;
12235 };
12236 CHECK_RESULT(ctx, result);
12237
12238 uint8 *curr_index = ctx->index;
12239 ctx->index = length_index;
12240
12241 result = kmip_encode_length(ctx, curr_index - value_index);
12242 CHECK_RESULT(ctx, result);
12243
12244 ctx->index = curr_index;
12245
12246 return(KMIP_OK);
12247 }
12248
12249 int
12250 kmip_encode_request_message(KMIP *ctx, const RequestMessage *value)
12251 {
12252 int result = 0;
12253 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_REQUEST_MESSAGE, KMIP_TYPE_STRUCTURE));
12254 CHECK_RESULT(ctx, result);
12255
12256 uint8 *length_index = ctx->index;
12257 uint8 *value_index = ctx->index += 4;
12258
12259 result = kmip_encode_request_header(ctx, value->request_header);
12260 CHECK_RESULT(ctx, result);
12261
12262 for(size_t i = 0; i < value->batch_count; i++)
12263 {
12264 result = kmip_encode_request_batch_item(ctx, &value->batch_items[i]);
12265 CHECK_RESULT(ctx, result);
12266 }
12267
12268 uint8 *curr_index = ctx->index;
12269 ctx->index = length_index;
12270
12271 result = kmip_encode_length(ctx, curr_index - value_index);
12272 CHECK_RESULT(ctx, result);
12273
12274 ctx->index = curr_index;
12275
12276 return(KMIP_OK);
12277 }
12278
12279 int
12280 kmip_encode_response_message(KMIP *ctx, const ResponseMessage *value)
12281 {
12282 int result = 0;
12283 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_RESPONSE_MESSAGE, KMIP_TYPE_STRUCTURE));
12284 CHECK_RESULT(ctx, result);
12285
12286 uint8 *length_index = ctx->index;
12287 uint8 *value_index = ctx->index += 4;
12288
12289 result = kmip_encode_response_header(ctx, value->response_header);
12290 CHECK_RESULT(ctx, result);
12291
12292 for(size_t i = 0; i < value->batch_count; i++)
12293 {
12294 result = kmip_encode_response_batch_item(ctx, &value->batch_items[i]);
12295 CHECK_RESULT(ctx, result);
12296 }
12297
12298 uint8 *curr_index = ctx->index;
12299 ctx->index = length_index;
12300
12301 result = kmip_encode_length(ctx, curr_index - value_index);
12302 CHECK_RESULT(ctx, result);
12303
12304 ctx->index = curr_index;
12305
12306 return(KMIP_OK);
12307 }
12308
12309 int
12310 kmip_encode_query_functions(KMIP *ctx, const Functions* value)
12311 {
12312 CHECK_ENCODE_ARGS(ctx, value);
12313
12314 int result = 0;
12315
12316 if(value->function_list != NULL)
12317 {
12318 LinkedListItem *curr = value->function_list->head;
12319 while(curr != NULL)
12320 {
12321 result = kmip_encode_enum(ctx, KMIP_TAG_QUERY_FUNCTION, *(int32 *)curr->data);
12322 CHECK_RESULT(ctx, result);
12323
12324 curr = curr->next;
12325 }
12326 }
12327
12328 return(KMIP_OK);
12329 }
12330 int
12331 kmip_encode_query_request_payload(KMIP *ctx, const QueryRequestPayload *value)
12332 {
12333 int result = 0;
12334 result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE));
12335 CHECK_RESULT(ctx, result);
12336
12337 uint8 *length_index = ctx->index;
12338 uint8 *value_index = ctx->index += 4;
12339
12340 if(value->functions != NULL)
12341 {
12342 result = kmip_encode_query_functions(ctx, value->functions);
12343 CHECK_RESULT(ctx, result);
12344 }
12345
12346 uint8 *curr_index = ctx->index;
12347 ctx->index = length_index;
12348
12349 kmip_encode_int32_be(ctx, curr_index - value_index);
12350
12351 ctx->index = curr_index;
12352
12353 return(KMIP_OK);
12354 }
12355
12356
12357 int
12358 kmip_encode_query_response_payload(KMIP *ctx, const QueryResponsePayload *value)
12359 {
12360 //TODO
12361 (void) ctx;
12362 (void) value;
12363 return(KMIP_NOT_IMPLEMENTED);
12364 }
12365
12366 /*
12367 Decoding Functions
12368 */
12369
12370 int
12371 kmip_decode_int8_be(KMIP *ctx, void *value)
12372 {
12373 CHECK_BUFFER_FULL(ctx, sizeof(int8));
12374
12375 int8 *i = (int8*)value;
12376
12377 *i = 0;
12378 *i = *ctx->index++;
12379
12380 return(KMIP_OK);
12381 }
12382
12383 int
12384 kmip_decode_int32_be(KMIP *ctx, void *value)
12385 {
12386 CHECK_BUFFER_FULL(ctx, sizeof(int32));
12387
12388 int32 *i = (int32*)value;
12389
12390 *i = 0;
12391 *i |= ((int32)*ctx->index++ << 24);
12392 *i |= ((int32)*ctx->index++ << 16);
12393 *i |= ((int32)*ctx->index++ << 8);
12394 *i |= ((int32)*ctx->index++ << 0);
12395
12396 return(KMIP_OK);
12397 }
12398
12399 int
12400 kmip_decode_int64_be(KMIP *ctx, void *value)
12401 {
12402 CHECK_BUFFER_FULL(ctx, sizeof(int64));
12403
12404 int64 *i = (int64*)value;
12405
12406 *i = 0;
12407 *i |= ((int64)*ctx->index++ << 56);
12408 *i |= ((int64)*ctx->index++ << 48);
12409 *i |= ((int64)*ctx->index++ << 40);
12410 *i |= ((int64)*ctx->index++ << 32);
12411 *i |= ((int64)*ctx->index++ << 24);
12412 *i |= ((int64)*ctx->index++ << 16);
12413 *i |= ((int64)*ctx->index++ << 8);
12414 *i |= ((int64)*ctx->index++ << 0);
12415
12416 return(KMIP_OK);
12417 }
12418
12419 int
12420 kmip_decode_length(KMIP *ctx, uint32 *value)
12421 {
12422 CHECK_BUFFER_FULL(ctx, 4);
12423
12424 kmip_decode_int32_be(ctx, value);
12425
12426 if(*value > INT_MAX)
12427 {
12428 HANDLE_FAILURE(ctx, KMIP_INVALID_LENGTH);
12429 }
12430
12431 return(KMIP_OK);
12432 }
12433
12434 int
12435 kmip_decode_integer(KMIP *ctx, enum tag t, int32 *value)
12436 {
12437 CHECK_BUFFER_FULL(ctx, 16);
12438
12439 int32 tag_type = 0;
12440 uint32 length = 0;
12441 int32 padding = 0;
12442
12443 kmip_decode_int32_be(ctx, &tag_type);
12444 CHECK_TAG_TYPE(ctx, tag_type, t, KMIP_TYPE_INTEGER);
12445
12446 kmip_decode_length(ctx, &length);
12447 CHECK_LENGTH(ctx, length, 4);
12448
12449 kmip_decode_int32_be(ctx, value);
12450
12451 kmip_decode_int32_be(ctx, &padding);
12452 CHECK_PADDING(ctx, padding);
12453
12454 return(KMIP_OK);
12455 }
12456
12457 int
12458 kmip_decode_long(KMIP *ctx, enum tag t, int64 *value)
12459 {
12460 CHECK_BUFFER_FULL(ctx, 16);
12461
12462 int32 tag_type = 0;
12463 uint32 length = 0;
12464
12465 kmip_decode_int32_be(ctx, &tag_type);
12466 CHECK_TAG_TYPE(ctx, tag_type, t, KMIP_TYPE_LONG_INTEGER);
12467
12468 kmip_decode_length(ctx, &length);
12469 CHECK_LENGTH(ctx, length, 8);
12470
12471 kmip_decode_int64_be(ctx, value);
12472
12473 return(KMIP_OK);
12474 }
12475
12476 int
12477 kmip_decode_enum(KMIP *ctx, enum tag t, void *value)
12478 {
12479 CHECK_BUFFER_FULL(ctx, 16);
12480
12481 int32 tag_type = 0;
12482 uint32 length = 0;
12483 int32 *v = (int32*)value;
12484 int32 padding = 0;
12485
12486 kmip_decode_int32_be(ctx, &tag_type);
12487 CHECK_TAG_TYPE(ctx, tag_type, t, KMIP_TYPE_ENUMERATION);
12488
12489 kmip_decode_length(ctx, &length);
12490 CHECK_LENGTH(ctx, length, 4);
12491
12492 kmip_decode_int32_be(ctx, v);
12493
12494 kmip_decode_int32_be(ctx, &padding);
12495 CHECK_PADDING(ctx, padding);
12496
12497 return(KMIP_OK);
12498 }
12499
12500 int
12501 kmip_decode_bool(KMIP *ctx, enum tag t, bool32 *value)
12502 {
12503 CHECK_BUFFER_FULL(ctx, 16);
12504
12505 int32 tag_type = 0;
12506 uint32 length = 0;
12507 int32 padding = 0;
12508
12509 kmip_decode_int32_be(ctx, &tag_type);
12510 CHECK_TAG_TYPE(ctx, tag_type, t, KMIP_TYPE_BOOLEAN);
12511
12512 kmip_decode_length(ctx, &length);
12513 CHECK_LENGTH(ctx, length, 8);
12514
12515 kmip_decode_int32_be(ctx, &padding);
12516 CHECK_PADDING(ctx, padding);
12517
12518 kmip_decode_int32_be(ctx, value);
12519 CHECK_BOOLEAN(ctx, *value);
12520
12521 return(KMIP_OK);
12522 }
12523
12524 int
12525 kmip_decode_text_string(KMIP *ctx, enum tag t, TextString *value)
12526 {
12527 CHECK_BUFFER_FULL(ctx, 8);
12528
12529 int32 tag_type = 0;
12530 uint32 length = 0;
12531 uint8 padding = 0;
12532 int8 spacer = 0;
12533
12534 kmip_decode_int32_be(ctx, &tag_type);
12535 CHECK_TAG_TYPE(ctx, tag_type, t, KMIP_TYPE_TEXT_STRING);
12536
12537 kmip_decode_length(ctx, &length);
12538 padding = CALCULATE_PADDING(length);
12539 CHECK_BUFFER_FULL(ctx, length + padding);
12540
12541 value->value = ctx->calloc_func(ctx->state, 1, length);
12542 value->size = length;
12543
12544 char *index = value->value;
12545
12546 for(uint32 i = 0; i < length; i++)
12547 {
12548 kmip_decode_int8_be(ctx, (int8*)index++);
12549 }
12550 for(uint8 i = 0; i < padding; i++)
12551 {
12552 kmip_decode_int8_be(ctx, &spacer);
12553 CHECK_PADDING(ctx, spacer);
12554 }
12555
12556 return(KMIP_OK);
12557 }
12558
12559 int
12560 kmip_decode_byte_string(KMIP *ctx, enum tag t, ByteString *value)
12561 {
12562 CHECK_BUFFER_FULL(ctx, 8);
12563
12564 int32 tag_type = 0;
12565 uint32 length = 0;
12566 uint8 padding = 0;
12567 int8 spacer = 0;
12568
12569 kmip_decode_int32_be(ctx, &tag_type);
12570 CHECK_TAG_TYPE(ctx, tag_type, t, KMIP_TYPE_BYTE_STRING);
12571
12572 kmip_decode_length(ctx, &length);
12573 padding = CALCULATE_PADDING(length);
12574 CHECK_BUFFER_FULL(ctx, length + padding);
12575
12576 value->value = ctx->calloc_func(ctx->state, 1, length);
12577 value->size = length;
12578
12579 uint8 *index = value->value;
12580
12581 for(uint32 i = 0; i < length; i++)
12582 {
12583 kmip_decode_int8_be(ctx, index++);
12584 }
12585 for(uint8 i = 0; i < padding; i++)
12586 {
12587 kmip_decode_int8_be(ctx, &spacer);
12588 CHECK_PADDING(ctx, spacer);
12589 }
12590
12591 return(KMIP_OK);
12592 }
12593
12594 int
12595 kmip_decode_date_time(KMIP *ctx, enum tag t, int64 *value)
12596 {
12597 CHECK_BUFFER_FULL(ctx, 16);
12598
12599 int32 tag_type = 0;
12600 uint32 length = 0;
12601
12602 kmip_decode_int32_be(ctx, &tag_type);
12603 CHECK_TAG_TYPE(ctx, tag_type, t, KMIP_TYPE_DATE_TIME);
12604
12605 kmip_decode_length(ctx, &length);
12606 CHECK_LENGTH(ctx, length, 8);
12607
12608 kmip_decode_int64_be(ctx, value);
12609
12610 return(KMIP_OK);
12611 }
12612
12613 int
12614 kmip_decode_interval(KMIP *ctx, enum tag t, uint32 *value)
12615 {
12616 CHECK_BUFFER_FULL(ctx, 16);
12617
12618 int32 tag_type = 0;
12619 uint32 length = 0;
12620 int32 padding = 0;
12621
12622 kmip_decode_int32_be(ctx, &tag_type);
12623 CHECK_TAG_TYPE(ctx, tag_type, t, KMIP_TYPE_INTERVAL);
12624
12625 kmip_decode_length(ctx, &length);
12626 CHECK_LENGTH(ctx, length, 4);
12627
12628 kmip_decode_int32_be(ctx, value);
12629
12630 kmip_decode_int32_be(ctx, &padding);
12631 CHECK_PADDING(ctx, padding);
12632
12633 return(KMIP_OK);
12634 }
12635
12636 int
12637 kmip_decode_name(KMIP *ctx, Name *value)
12638 {
12639 CHECK_BUFFER_FULL(ctx, 8);
12640
12641 int result = 0;
12642 int32 tag_type = 0;
12643 uint32 length = 0;
12644
12645 kmip_decode_int32_be(ctx, &tag_type);
12646 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_NAME, KMIP_TYPE_STRUCTURE);
12647
12648 kmip_decode_length(ctx, &length);
12649 CHECK_BUFFER_FULL(ctx, length);
12650
12651 value->value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
12652
12653 result = kmip_decode_text_string(ctx, KMIP_TAG_NAME_VALUE, value->value);
12654 CHECK_RESULT(ctx, result);
12655
12656 result = kmip_decode_enum(ctx, KMIP_TAG_NAME_TYPE, (int32*)&value->type);
12657 CHECK_RESULT(ctx, result);
12658 CHECK_ENUM(ctx, KMIP_TAG_NAME_TYPE, value->type);
12659
12660 return(KMIP_OK);
12661 }
12662
12663 int
12664 kmip_decode_attribute_name(KMIP *ctx, enum attribute_type *value)
12665 {
12666 int result = 0;
12667 enum tag t = KMIP_TAG_ATTRIBUTE_NAME;
12668 TextString n = {0};
12669
12670 result = kmip_decode_text_string(ctx, t, &n);
12671 CHECK_RESULT(ctx, result);
12672
12673 if((n.size == 32) && (strncmp(n.value, "Application Specific Information", 32) == 0))
12674 {
12675 *value = KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION;
12676 }
12677 else if((n.size == 17) && (strncmp(n.value, "Unique Identifier", 17) == 0))
12678 {
12679 *value = KMIP_ATTR_UNIQUE_IDENTIFIER;
12680 }
12681 else if((n.size == 4) && (strncmp(n.value, "Name", 4) == 0))
12682 {
12683 *value = KMIP_ATTR_NAME;
12684 }
12685 else if((n.size == 11) && (strncmp(n.value, "Object Type", 11) == 0))
12686 {
12687 *value = KMIP_ATTR_OBJECT_TYPE;
12688 }
12689 else if((n.size == 23) && (strncmp(n.value, "Cryptographic Algorithm", 23) == 0))
12690 {
12691 *value = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
12692 }
12693 else if((n.size == 20) && (strncmp(n.value, "Cryptographic Length", 20) == 0))
12694 {
12695 *value = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
12696 }
12697 else if((n.size == 21) && (strncmp(n.value, "Operation Policy Name", 21) == 0))
12698 {
12699 *value = KMIP_ATTR_OPERATION_POLICY_NAME;
12700 }
12701 else if((n.size == 24) && (strncmp(n.value, "Cryptographic Usage Mask", 24) == 0))
12702 {
12703 *value = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
12704 }
12705 else if((n.size == 5) && (strncmp(n.value, "State", 5) == 0))
12706 {
12707 *value = KMIP_ATTR_STATE;
12708 }
12709 else if((n.size == 12) && (strncmp(n.value, "Object Group", 12) == 0))
12710 {
12711 *value = KMIP_ATTR_OBJECT_GROUP;
12712 }
12713 else if((n.size == 15) && (strncmp(n.value, "Activation Date", 15) == 0))
12714 {
12715 *value = KMIP_ATTR_ACTIVATION_DATE;
12716 }
12717 else if((n.size == 17) && (strncmp(n.value, "Deactivation Date", 17) == 0))
12718 {
12719 *value = KMIP_ATTR_DEACTIVATION_DATE;
12720 }
12721 else if((18 == n.size) && (strncmp(n.value, "Process Start Date", 18) == 0))
12722 {
12723 *value = KMIP_ATTR_PROCESS_START_DATE;
12724 }
12725 else if((17 == n.size) && (strncmp(n.value, "Protect Stop Date", 17) == 0))
12726 {
12727 *value = KMIP_ATTR_PROTECT_STOP_DATE;
12728 }
12729 else if((24 == n.size) && (strncmp(n.value, "Cryptographic Parameters", 24) == 0))
12730 {
12731 *value = KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS;
12732 }
12733 /* TODO (ph) Add all remaining attributes here. */
12734 else
12735 {
12736 kmip_push_error_frame(ctx, __func__, __LINE__);
12737 kmip_free_text_string(ctx, &n);
12738 return(KMIP_ERROR_ATTR_UNSUPPORTED);
12739 }
12740
12741 kmip_free_text_string(ctx, &n);
12742 return(KMIP_OK);
12743 }
12744
12745 int
12746 kmip_decode_protection_storage_masks(KMIP *ctx, ProtectionStorageMasks *value)
12747 {
12748 CHECK_DECODE_ARGS(ctx, value);
12749 CHECK_KMIP_VERSION(ctx, KMIP_2_0);
12750 CHECK_BUFFER_FULL(ctx, 8);
12751
12752 int result = 0;
12753 int32 tag_type = 0;
12754 uint32 length = 0;
12755
12756 result = kmip_decode_int32_be(ctx, &tag_type);
12757 CHECK_RESULT(ctx, result);
12758 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_PROTECTION_STORAGE_MASKS, KMIP_TYPE_STRUCTURE);
12759
12760 result = kmip_decode_length(ctx, &length);
12761 CHECK_RESULT(ctx, result);
12762 CHECK_BUFFER_FULL(ctx, length);
12763
12764 value->masks = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
12765 CHECK_NEW_MEMORY(ctx, value->masks, sizeof(LinkedList), "LinkedList");
12766
12767 uint32 tag = kmip_peek_tag(ctx);
12768 while(tag == KMIP_TAG_PROTECTION_STORAGE_MASK)
12769 {
12770 LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
12771 CHECK_NEW_MEMORY(ctx, item, sizeof(LinkedListItem), "LinkedListItem");
12772 kmip_linked_list_enqueue(value->masks, item);
12773
12774 item->data = ctx->calloc_func(ctx->state, 1, sizeof(int32));
12775 CHECK_NEW_MEMORY(ctx, item->data, sizeof(int32), "Protection Storage Mask");
12776
12777 result = kmip_decode_integer(ctx, KMIP_TAG_PROTECTION_STORAGE_MASK, (int32 *)item->data);
12778 CHECK_RESULT(ctx, result);
12779
12780 tag = kmip_peek_tag(ctx);
12781 }
12782
12783 return(KMIP_OK);
12784 }
12785
12786 int
12787 kmip_decode_attribute_v1(KMIP *ctx, Attribute *value)
12788 {
12789 CHECK_BUFFER_FULL(ctx, 8);
12790
12791 kmip_init_attribute(value);
12792
12793 int result = 0;
12794 int32 tag_type = 0;
12795 uint32 length = 0;
12796
12797 kmip_decode_int32_be(ctx, &tag_type);
12798 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_ATTRIBUTE, KMIP_TYPE_STRUCTURE);
12799
12800 kmip_decode_length(ctx, &length);
12801 CHECK_BUFFER_FULL(ctx, length);
12802
12803 result = kmip_decode_attribute_name(ctx, &value->type);
12804 CHECK_RESULT(ctx, result);
12805
12806 if(kmip_is_tag_next(ctx, KMIP_TAG_ATTRIBUTE_INDEX))
12807 {
12808 result = kmip_decode_integer(ctx, KMIP_TAG_ATTRIBUTE_INDEX, &value->index);
12809 CHECK_RESULT(ctx, result);
12810 }
12811
12812 uint8 *curr_index = 0;
12813 uint8 *tag_index = ctx->index;
12814 enum tag t = KMIP_TAG_ATTRIBUTE_VALUE;
12815
12816 switch(value->type)
12817 {
12818 case KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION:
12819 {
12820 /* TODO (ph) Like encoding, this is messy. Better solution? */
12821 if(kmip_is_tag_type_next(ctx, KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE))
12822 {
12823 /* NOTE (ph) Decoding structures will fail if the structure tag */
12824 /* is not present in the encoding. Temporarily swap the tags, */
12825 /* decode the structure, and then swap the tags back to */
12826 /* preserve the encoding. The tag/type check above guarantees */
12827 /* space exists for this to succeed. */
12828 kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_APPLICATION_SPECIFIC_INFORMATION, KMIP_TYPE_STRUCTURE));
12829 ctx->index = tag_index;
12830 value->value = ctx->calloc_func(ctx->state, 1, sizeof(ApplicationSpecificInformation));
12831 CHECK_NEW_MEMORY(ctx, value->value, sizeof(ApplicationSpecificInformation), "ApplicationSpecificInformation structure");
12832 result = kmip_decode_application_specific_information(ctx, (ApplicationSpecificInformation*)value->value);
12833
12834 curr_index = ctx->index;
12835 ctx->index = tag_index;
12836
12837 kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE));
12838 ctx->index = curr_index;
12839 }
12840 else
12841 {
12842 result = KMIP_TAG_MISMATCH;
12843 }
12844
12845 CHECK_RESULT(ctx, result);
12846 }
12847 break;
12848
12849 case KMIP_ATTR_UNIQUE_IDENTIFIER:
12850 value->value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
12851 CHECK_NEW_MEMORY(ctx, value->value, sizeof(TextString), "UniqueIdentifier text string");
12852 result = kmip_decode_text_string(ctx, t, (TextString*)value->value);
12853 CHECK_RESULT(ctx, result);
12854 break;
12855
12856 case KMIP_ATTR_NAME:
12857 {
12858 /* TODO (ph) Like encoding, this is messy. Better solution? */
12859 if(kmip_is_tag_type_next(ctx, KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE))
12860 {
12861 /* NOTE (ph) Decoding structures will fail if the structure tag */
12862 /* is not present in the encoding. Temporarily swap the tags, */
12863 /* decode the structure, and then swap the tags back to */
12864 /* preserve the encoding. The tag/type check above guarantees */
12865 /* space exists for this to succeed. */
12866 kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_NAME, KMIP_TYPE_STRUCTURE));
12867 ctx->index = tag_index;
12868 value->value = ctx->calloc_func(ctx->state, 1, sizeof(Name));
12869 CHECK_NEW_MEMORY(ctx, value->value, sizeof(Name), "Name structure");
12870 result = kmip_decode_name(ctx, (Name*)value->value);
12871
12872 curr_index = ctx->index;
12873 ctx->index = tag_index;
12874
12875 kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE));
12876 ctx->index = curr_index;
12877 }
12878 else
12879 {
12880 result = KMIP_TAG_MISMATCH;
12881 }
12882
12883 CHECK_RESULT(ctx, result);
12884 }
12885 break;
12886
12887 case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
12888 {
12889 /* TODO (ph) Like encoding, this is messy. Better solution? */
12890 if(kmip_is_tag_type_next(ctx, KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE))
12891 {
12892 /* NOTE (ph) Decoding structures will fail if the structure tag */
12893 /* is not present in the encoding. Temporarily swap the tags, */
12894 /* decode the structure, and then swap the tags back to */
12895 /* preserve the encoding. The tag/type check above guarantees */
12896 /* space exists for this to succeed. */
12897 kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_CRYPTOGRAPHIC_PARAMETERS, KMIP_TYPE_STRUCTURE));
12898 ctx->index = tag_index;
12899 value->value = ctx->calloc_func(ctx->state, 1, sizeof(CryptographicParameters));
12900 CHECK_NEW_MEMORY(ctx, value->value, sizeof(CryptographicParameters), "CryptographicParameters structure");
12901 kmip_init_cryptographic_parameters((CryptographicParameters*)value->value);
12902 result = kmip_decode_cryptographic_parameters(ctx, (CryptographicParameters*)value->value);
12903
12904 curr_index = ctx->index;
12905 ctx->index = tag_index;
12906
12907 kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE));
12908 ctx->index = curr_index;
12909 }
12910 else
12911 {
12912 result = KMIP_TAG_MISMATCH;
12913 }
12914
12915 CHECK_RESULT(ctx, result);
12916 } break;
12917
12918 case KMIP_ATTR_OBJECT_TYPE:
12919 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
12920 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "ObjectType enumeration");
12921 result = kmip_decode_enum(ctx, t, (int32 *)value->value);
12922 CHECK_RESULT(ctx, result);
12923 CHECK_ENUM(ctx, KMIP_TAG_OBJECT_TYPE, *(int32 *)value->value);
12924 break;
12925
12926 case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
12927 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
12928 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "CryptographicAlgorithm enumeration");
12929 result = kmip_decode_enum(ctx, t, (int32 *)value->value);
12930 CHECK_RESULT(ctx, result);
12931 CHECK_ENUM(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM, *(int32 *)value->value);
12932 break;
12933
12934 case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
12935 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
12936 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "CryptographicLength integer");
12937 result = kmip_decode_integer(ctx, t, (int32 *)value->value);
12938 CHECK_RESULT(ctx, result);
12939 break;
12940
12941 case KMIP_ATTR_OPERATION_POLICY_NAME:
12942 value->value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
12943 CHECK_NEW_MEMORY(ctx, value->value, sizeof(TextString), "OperationPolicyName text string");
12944 result = kmip_decode_text_string(ctx, t, (TextString*)value->value);
12945 CHECK_RESULT(ctx, result);
12946 break;
12947
12948 case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
12949 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
12950 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "CryptographicUsageMask integer");
12951 result = kmip_decode_integer(ctx, t, (int32 *)value->value);
12952 CHECK_RESULT(ctx, result);
12953 break;
12954
12955 case KMIP_ATTR_STATE:
12956 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
12957 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "State enumeration");
12958 result = kmip_decode_enum(ctx, t, (int32 *)value->value);
12959 CHECK_RESULT(ctx, result);
12960 CHECK_ENUM(ctx, KMIP_TAG_STATE, *(int32 *)value->value);
12961 break;
12962
12963 case KMIP_ATTR_OBJECT_GROUP:
12964 {
12965 value->value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
12966 CHECK_NEW_MEMORY(ctx, value->value, sizeof(TextString), "ObjectGroup text string");
12967 result = kmip_decode_text_string(ctx, t, (TextString*)value->value);
12968 CHECK_RESULT(ctx, result);
12969 }
12970 break;
12971
12972 case KMIP_ATTR_ACTIVATION_DATE:
12973 {
12974 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int64));
12975 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int64), "ActivationDate date time");
12976
12977 result = kmip_decode_date_time(ctx, t, (int64*)value->value);
12978 CHECK_RESULT(ctx, result);
12979 } break;
12980
12981 case KMIP_ATTR_DEACTIVATION_DATE:
12982 {
12983 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int64));
12984 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int64), "DeactivationDate date time");
12985
12986 result = kmip_decode_date_time(ctx, t, (int64*)value->value);
12987 CHECK_RESULT(ctx, result);
12988 } break;
12989
12990 case KMIP_ATTR_PROCESS_START_DATE:
12991 {
12992 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int64));
12993 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int64), "ProcessStartDate date time");
12994
12995 result = kmip_decode_date_time(ctx, t, (int64*)value->value);
12996 CHECK_RESULT(ctx, result);
12997 } break;
12998
12999 case KMIP_ATTR_PROTECT_STOP_DATE:
13000 {
13001 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int64));
13002 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int64), "ProtectStopDate date time");
13003
13004 result = kmip_decode_date_time(ctx, t, (int64*)value->value);
13005 CHECK_RESULT(ctx, result);
13006 } break;
13007
13008 default:
13009 kmip_push_error_frame(ctx, __func__, __LINE__);
13010 return(KMIP_ERROR_ATTR_UNSUPPORTED);
13011 break;
13012 };
13013 CHECK_RESULT(ctx, result);
13014
13015 return(KMIP_OK);
13016 }
13017
13018 int
13019 kmip_decode_attribute_v2(KMIP *ctx, Attribute *value)
13020 {
13021 CHECK_DECODE_ARGS(ctx, value);
13022 CHECK_KMIP_VERSION(ctx, KMIP_2_0);
13023
13024 kmip_init_attribute(value);
13025
13026 int result = 0;
13027 uint32 tag = kmip_peek_tag(ctx);
13028 if(tag == 0)
13029 {
13030 /* Record an error for an underfull buffer here and return. */
13031 }
13032
13033 CHECK_RESULT(ctx, result);
13034
13035 switch(tag)
13036 {
13037 case KMIP_TAG_UNIQUE_IDENTIFIER:
13038 {
13039 value->type = KMIP_ATTR_UNIQUE_IDENTIFIER;
13040 value->value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
13041 CHECK_NEW_MEMORY(ctx, value->value, sizeof(TextString), "UniqueIdentifier text string");
13042
13043 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, (TextString *)value->value);
13044 CHECK_RESULT(ctx, result);
13045 }
13046 break;
13047
13048 case KMIP_TAG_NAME:
13049 {
13050 value->type = KMIP_ATTR_NAME;
13051 value->value = ctx->calloc_func(ctx->state, 1, sizeof(Name));
13052 CHECK_NEW_MEMORY(ctx, value->value, sizeof(Name), "Name structure");
13053
13054 result = kmip_decode_name(ctx, (Name *)value->value);
13055 CHECK_RESULT(ctx, result);
13056 }
13057 break;
13058
13059 case KMIP_TAG_OBJECT_TYPE:
13060 {
13061 value->type = KMIP_ATTR_OBJECT_TYPE;
13062 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
13063 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "ObjectType enumeration");
13064
13065 result = kmip_decode_enum(ctx, KMIP_TAG_OBJECT_TYPE, (int32 *)value->value);
13066 CHECK_RESULT(ctx, result);
13067
13068 CHECK_ENUM(ctx, KMIP_TAG_OBJECT_TYPE, *(int32 *)value->value);
13069 }
13070 break;
13071
13072 case KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM:
13073 {
13074 value->type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
13075 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
13076 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "CrypographicAlgorithm enumeration");
13077
13078 result = kmip_decode_enum(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM, (int32 *)value->value);
13079 CHECK_RESULT(ctx, result);
13080
13081 CHECK_ENUM(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM, *(int32 *)value->value);
13082 }
13083 break;
13084
13085 case KMIP_TAG_CRYPTOGRAPHIC_LENGTH:
13086 {
13087 value->type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
13088 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
13089 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "CryptographicLength integer");
13090
13091 result = kmip_decode_integer(ctx, KMIP_TAG_CRYPTOGRAPHIC_LENGTH, (int32 *)value->value);
13092 CHECK_RESULT(ctx, result);
13093 }
13094 break;
13095
13096 case KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK:
13097 {
13098 value->type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
13099 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
13100 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "CryptographicUsageMask integer");
13101
13102 result = kmip_decode_integer(ctx, KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK, (int32 *)value->value);
13103 CHECK_RESULT(ctx, result);
13104 }
13105 break;
13106
13107 case KMIP_TAG_STATE:
13108 {
13109 value->type = KMIP_ATTR_STATE;
13110 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int32));
13111 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int32), "State enumeration");
13112
13113 result = kmip_decode_enum(ctx, KMIP_TAG_STATE, (int32 *)value->value);
13114 CHECK_RESULT(ctx, result);
13115
13116 CHECK_ENUM(ctx, KMIP_TAG_STATE, *(int32 *)value->value);
13117 }
13118 break;
13119
13120 case KMIP_TAG_APPLICATION_SPECIFIC_INFORMATION:
13121 {
13122 value->type = KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION;
13123 value->value = ctx->calloc_func(ctx->state, 1, sizeof(ApplicationSpecificInformation));
13124 CHECK_NEW_MEMORY(ctx, value->value, sizeof(ApplicationSpecificInformation), "ApplicationSpecificInformation structure");
13125
13126 result = kmip_decode_application_specific_information(ctx, value->value);
13127 CHECK_RESULT(ctx, result);
13128 }
13129 break;
13130
13131 case KMIP_TAG_OBJECT_GROUP:
13132 {
13133 value->type = KMIP_ATTR_OBJECT_GROUP;
13134 value->value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
13135 CHECK_NEW_MEMORY(ctx, value->value, sizeof(TextString), "ObjectGroup text string");
13136
13137 result = kmip_decode_text_string(ctx, KMIP_TAG_OBJECT_GROUP, (TextString*)value->value);
13138 CHECK_RESULT(ctx, result);
13139 }
13140 break;
13141
13142 case KMIP_TAG_ACTIVATION_DATE:
13143 {
13144 value->type = KMIP_ATTR_ACTIVATION_DATE;
13145 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int64));
13146 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int64), "ActivationDate date time");
13147
13148 result = kmip_decode_date_time(ctx, KMIP_TAG_ACTIVATION_DATE, (int64*)value->value);
13149 CHECK_RESULT(ctx, result);
13150 } break;
13151
13152 case KMIP_TAG_DEACTIVATION_DATE:
13153 {
13154 value->type = KMIP_ATTR_DEACTIVATION_DATE;
13155 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int64));
13156 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int64), "DeactivationDate date time");
13157
13158 result = kmip_decode_date_time(ctx, KMIP_TAG_DEACTIVATION_DATE, (int64*)value->value);
13159 CHECK_RESULT(ctx, result);
13160 } break;
13161
13162 case KMIP_TAG_PROCESS_START_DATE:
13163 {
13164 value->type = KMIP_ATTR_PROCESS_START_DATE;
13165 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int64));
13166 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int64), "ProcessStartDate date time");
13167
13168 result = kmip_decode_date_time(ctx, tag, (int64*)value->value);
13169 CHECK_RESULT(ctx, result);
13170 } break;
13171
13172 case KMIP_TAG_PROTECT_STOP_DATE:
13173 {
13174 value->type = KMIP_ATTR_PROTECT_STOP_DATE;
13175 value->value = ctx->calloc_func(ctx->state, 1, sizeof(int64));
13176 CHECK_NEW_MEMORY(ctx, value->value, sizeof(int64), "ProtectStopDate date time");
13177
13178 result = kmip_decode_date_time(ctx, tag, (int64*)value->value);
13179 CHECK_RESULT(ctx, result);
13180 } break;
13181
13182 case KMIP_TAG_CRYPTOGRAPHIC_PARAMETERS:
13183 {
13184 value->type = KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS;
13185 value->value = ctx->calloc_func(ctx->state, 1, sizeof(CryptographicParameters));
13186 CHECK_NEW_MEMORY(ctx, value->value, sizeof(CryptographicParameters), "CryptographicParameters structure");
13187
13188 result = kmip_decode_cryptographic_parameters(ctx, value->value);
13189 CHECK_RESULT(ctx, result);
13190 } break;
13191
13192 default:
13193 {
13194 kmip_push_error_frame(ctx, __func__, __LINE__);
13195 return(KMIP_ERROR_ATTR_UNSUPPORTED);
13196 }
13197 break;
13198 };
13199
13200 return(KMIP_OK);
13201 }
13202
13203 int
13204 kmip_decode_attribute(KMIP *ctx, Attribute *value)
13205 {
13206 CHECK_DECODE_ARGS(ctx, value);
13207
13208 if(ctx->version < KMIP_2_0)
13209 {
13210 return(kmip_decode_attribute_v1(ctx, value));
13211 }
13212 else
13213 {
13214 return(kmip_decode_attribute_v2(ctx, value));
13215 }
13216 }
13217
13218 int
13219 kmip_decode_attributes(KMIP *ctx, Attributes *value)
13220 {
13221 CHECK_DECODE_ARGS(ctx, value);
13222 CHECK_KMIP_VERSION(ctx, KMIP_2_0);
13223 CHECK_BUFFER_FULL(ctx, 8);
13224
13225 int result = 0;
13226 int32 tag_type = 0;
13227 uint32 length = 0;
13228
13229 result = kmip_decode_int32_be(ctx, &tag_type);
13230 CHECK_RESULT(ctx, result);
13231 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_ATTRIBUTES, KMIP_TYPE_STRUCTURE);
13232
13233 result = kmip_decode_length(ctx, &length);
13234 CHECK_RESULT(ctx, result);
13235 CHECK_BUFFER_FULL(ctx, length);
13236
13237 value->attribute_list = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
13238 CHECK_NEW_MEMORY(ctx, value->attribute_list, sizeof(LinkedList), "LinkedList");
13239
13240 uint32 tag = kmip_peek_tag(ctx);
13241 while(tag != 0 && kmip_is_attribute_tag(tag))
13242 {
13243 LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
13244 CHECK_NEW_MEMORY(ctx, item, sizeof(LinkedListItem), "LinkedListItem");
13245 kmip_linked_list_enqueue(value->attribute_list, item);
13246
13247 item->data = ctx->calloc_func(ctx->state, 1, sizeof(Attribute));
13248 CHECK_NEW_MEMORY(ctx, item->data, sizeof(Attribute), "Attribute");
13249
13250 result = kmip_decode_attribute(ctx, (Attribute *)item->data);
13251 CHECK_RESULT(ctx, result);
13252
13253 tag = kmip_peek_tag(ctx);
13254 }
13255
13256 return(KMIP_OK);
13257 }
13258
13259 int
13260 kmip_decode_template_attribute(KMIP *ctx, TemplateAttribute *value)
13261 {
13262 CHECK_BUFFER_FULL(ctx, 8);
13263
13264 int result = 0;
13265 int32 tag_type = 0;
13266 uint32 length = 0;
13267
13268 kmip_decode_int32_be(ctx, &tag_type);
13269 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_TEMPLATE_ATTRIBUTE, KMIP_TYPE_STRUCTURE);
13270
13271 kmip_decode_length(ctx, &length);
13272 CHECK_BUFFER_FULL(ctx, length);
13273
13274 value->name_count = kmip_get_num_items_next(ctx, KMIP_TAG_NAME);
13275 if(value->name_count > 0)
13276 {
13277 value->names = ctx->calloc_func(ctx->state, value->name_count, sizeof(Name));
13278 CHECK_NEW_MEMORY(ctx, value->names, value->name_count * sizeof(Name), "sequence of Name structures");
13279
13280 for(size_t i = 0; i < value->name_count; i++)
13281 {
13282 result = kmip_decode_name(ctx, &value->names[i]);
13283 CHECK_RESULT(ctx, result);
13284 }
13285 }
13286
13287 value->attribute_count = kmip_get_num_items_next(ctx, KMIP_TAG_ATTRIBUTE);
13288 if(value->attribute_count > 0)
13289 {
13290 value->attributes = ctx->calloc_func(ctx->state, value->attribute_count, sizeof(Attribute));
13291 CHECK_NEW_MEMORY(ctx, value->attributes, value->attribute_count * sizeof(Attribute), "sequence of Attribute structures");
13292
13293 for(size_t i = 0; i < value->attribute_count; i++)
13294 {
13295 result = kmip_decode_attribute(ctx, &value->attributes[i]);
13296 CHECK_RESULT(ctx, result);
13297 }
13298 }
13299
13300 return(KMIP_OK);
13301 }
13302
13303 int
13304 kmip_decode_protocol_version(KMIP *ctx, ProtocolVersion *value)
13305 {
13306 CHECK_BUFFER_FULL(ctx, 40);
13307
13308 int result = 0;
13309 int32 tag_type = 0;
13310 uint32 length = 0;
13311
13312 kmip_decode_int32_be(ctx, &tag_type);
13313 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_PROTOCOL_VERSION, KMIP_TYPE_STRUCTURE);
13314
13315 kmip_decode_length(ctx, &length);
13316 CHECK_LENGTH(ctx, length, 32);
13317
13318 result = kmip_decode_integer(ctx, KMIP_TAG_PROTOCOL_VERSION_MAJOR, &value->major);
13319 CHECK_RESULT(ctx, result);
13320
13321 result = kmip_decode_integer(ctx, KMIP_TAG_PROTOCOL_VERSION_MINOR, &value->minor);
13322 CHECK_RESULT(ctx, result);
13323
13324 return(KMIP_OK);
13325 }
13326
13327 int
13328 kmip_decode_transparent_symmetric_key(KMIP *ctx, TransparentSymmetricKey *value)
13329 {
13330 CHECK_BUFFER_FULL(ctx, 8);
13331
13332 int result = 0;
13333 int32 tag_type = 0;
13334 uint32 length = 0;
13335
13336 kmip_decode_int32_be(ctx, &tag_type);
13337 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_KEY_MATERIAL, KMIP_TYPE_STRUCTURE);
13338
13339 kmip_decode_length(ctx, &length);
13340 CHECK_BUFFER_FULL(ctx, length);
13341
13342 value->key = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
13343 CHECK_NEW_MEMORY(ctx, value->key, sizeof(ByteString), "Key byte string");
13344
13345 result = kmip_decode_byte_string(ctx, KMIP_TAG_KEY, value->key);
13346 CHECK_RESULT(ctx, result);
13347
13348 return(KMIP_OK);
13349 }
13350
13351 int
13352 kmip_decode_key_material(KMIP *ctx, enum key_format_type format, void **value)
13353 {
13354 int result = 0;
13355
13356 switch(format)
13357 {
13358 case KMIP_KEYFORMAT_RAW:
13359 case KMIP_KEYFORMAT_OPAQUE:
13360 case KMIP_KEYFORMAT_PKCS1:
13361 case KMIP_KEYFORMAT_PKCS8:
13362 case KMIP_KEYFORMAT_X509:
13363 case KMIP_KEYFORMAT_EC_PRIVATE_KEY:
13364 *value = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
13365 CHECK_NEW_MEMORY(ctx, *value, sizeof(ByteString), "KeyMaterial byte string");
13366 result = kmip_decode_byte_string(ctx, KMIP_TAG_KEY_MATERIAL, (ByteString*)*value);
13367 CHECK_RESULT(ctx, result);
13368 return(KMIP_OK);
13369 break;
13370
13371 default:
13372 break;
13373 };
13374
13375 switch(format)
13376 {
13377 case KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY:
13378 *value = ctx->calloc_func(ctx->state, 1, sizeof(TransparentSymmetricKey));
13379 CHECK_NEW_MEMORY(ctx, *value, sizeof(TransparentSymmetricKey), "TransparentSymmetricKey structure");
13380 result = kmip_decode_transparent_symmetric_key(ctx, (TransparentSymmetricKey*)*value);
13381 CHECK_RESULT(ctx, result);
13382 break;
13383
13384 /* TODO (ph) The rest require BigInteger support. */
13385
13386 case KMIP_KEYFORMAT_TRANS_DSA_PRIVATE_KEY:
13387 case KMIP_KEYFORMAT_TRANS_DSA_PUBLIC_KEY:
13388 case KMIP_KEYFORMAT_TRANS_RSA_PRIVATE_KEY:
13389 case KMIP_KEYFORMAT_TRANS_RSA_PUBLIC_KEY:
13390 case KMIP_KEYFORMAT_TRANS_DH_PRIVATE_KEY:
13391 case KMIP_KEYFORMAT_TRANS_DH_PUBLIC_KEY:
13392 case KMIP_KEYFORMAT_TRANS_ECDSA_PRIVATE_KEY:
13393 case KMIP_KEYFORMAT_TRANS_ECDSA_PUBLIC_KEY:
13394 case KMIP_KEYFORMAT_TRANS_ECDH_PRIVATE_KEY:
13395 case KMIP_KEYFORMAT_TRANS_ECDH_PUBLIC_KEY:
13396 case KMIP_KEYFORMAT_TRANS_ECMQV_PRIVATE_KEY:
13397 case KMIP_KEYFORMAT_TRANS_ECMQV_PUBLIC_KEY:
13398 default:
13399 kmip_push_error_frame(ctx, __func__, __LINE__);
13400 return(KMIP_NOT_IMPLEMENTED);
13401 break;
13402 };
13403
13404 return(KMIP_OK);
13405 }
13406
13407 int
13408 kmip_decode_key_value(KMIP *ctx, enum key_format_type format, KeyValue *value)
13409 {
13410 CHECK_BUFFER_FULL(ctx, 8);
13411
13412 int result = 0;
13413 int32 tag_type = 0;
13414 uint32 length = 0;
13415
13416 kmip_decode_int32_be(ctx, &tag_type);
13417 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_KEY_VALUE, KMIP_TYPE_STRUCTURE);
13418
13419 kmip_decode_length(ctx, &length);
13420 CHECK_BUFFER_FULL(ctx, length);
13421
13422 result = kmip_decode_key_material(ctx, format, &value->key_material);
13423 CHECK_RESULT(ctx, result);
13424
13425 value->attribute_count = kmip_get_num_items_next(ctx, KMIP_TAG_ATTRIBUTE);
13426 if(value->attribute_count > 0)
13427 {
13428 value->attributes = ctx->calloc_func(ctx->state, value->attribute_count, sizeof(Attribute));
13429 CHECK_NEW_MEMORY(ctx, value->attributes, value->attribute_count * sizeof(Attribute), "sequence of Attribute structures");
13430
13431 for(size_t i = 0; i < value->attribute_count; i++)
13432 {
13433 result = kmip_decode_attribute(ctx, &value->attributes[i]);
13434 CHECK_RESULT(ctx, result);
13435 }
13436 }
13437
13438 return(KMIP_OK);
13439 }
13440
13441 int
13442 kmip_decode_application_specific_information(KMIP *ctx, ApplicationSpecificInformation *value)
13443 {
13444 CHECK_BUFFER_FULL(ctx, 8);
13445
13446 kmip_init_application_specific_information(value);
13447
13448 int result = 0;
13449 int32 tag_type = 0;
13450 uint32 length = 0;
13451
13452 kmip_decode_int32_be(ctx, &tag_type);
13453 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_APPLICATION_SPECIFIC_INFORMATION, KMIP_TYPE_STRUCTURE);
13454
13455 kmip_decode_length(ctx, &length);
13456 CHECK_BUFFER_FULL(ctx, length);
13457
13458 if(kmip_is_tag_next(ctx, KMIP_TAG_APPLICATION_NAMESPACE))
13459 {
13460 value->application_namespace = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
13461 CHECK_NEW_MEMORY(ctx, value->application_namespace, sizeof(TextString), "Application Namespace text string");
13462
13463 result = kmip_decode_text_string(ctx, KMIP_TAG_APPLICATION_NAMESPACE, value->application_namespace);
13464 CHECK_RESULT(ctx, result);
13465 }
13466 else
13467 {
13468 kmip_set_error_message(ctx, "The ApplicationSpecificInformation encoding is missing the application name field.");
13469 kmip_push_error_frame(ctx, __func__, __LINE__);
13470 return(KMIP_INVALID_ENCODING);
13471 }
13472
13473 if(kmip_is_tag_next(ctx, KMIP_TAG_APPLICATION_DATA))
13474 {
13475 value->application_data = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
13476 CHECK_NEW_MEMORY(ctx, value->application_data, sizeof(TextString), "Application Data text string");
13477
13478 result = kmip_decode_text_string(ctx, KMIP_TAG_APPLICATION_DATA, value->application_data);
13479 CHECK_RESULT(ctx, result);
13480 }
13481 else
13482 {
13483 if(ctx->version < KMIP_1_3)
13484 {
13485 kmip_set_error_message(ctx, "The ApplicationSpecificInformation encoding is missing the application data field.");
13486 kmip_push_error_frame(ctx, __func__, __LINE__);
13487 return(KMIP_INVALID_ENCODING);
13488 }
13489 }
13490
13491 return(KMIP_OK);
13492 }
13493
13494 int
13495 kmip_decode_cryptographic_parameters(KMIP *ctx, CryptographicParameters *value)
13496 {
13497 CHECK_BUFFER_FULL(ctx, 8);
13498
13499 kmip_init_cryptographic_parameters(value);
13500
13501 int result = 0;
13502 int32 tag_type = 0;
13503 uint32 length = 0;
13504
13505 kmip_decode_int32_be(ctx, &tag_type);
13506 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_CRYPTOGRAPHIC_PARAMETERS, KMIP_TYPE_STRUCTURE);
13507
13508 kmip_decode_length(ctx, &length);
13509 CHECK_BUFFER_FULL(ctx, length);
13510
13511 if(kmip_is_tag_next(ctx, KMIP_TAG_BLOCK_CIPHER_MODE))
13512 {
13513 result = kmip_decode_enum(ctx, KMIP_TAG_BLOCK_CIPHER_MODE, &value->block_cipher_mode);
13514 CHECK_RESULT(ctx, result);
13515 CHECK_ENUM(ctx, KMIP_TAG_BLOCK_CIPHER_MODE, value->block_cipher_mode);
13516 }
13517
13518 if(kmip_is_tag_next(ctx, KMIP_TAG_PADDING_METHOD))
13519 {
13520 result = kmip_decode_enum(ctx, KMIP_TAG_PADDING_METHOD, &value->padding_method);
13521 CHECK_RESULT(ctx, result);
13522 CHECK_ENUM(ctx, KMIP_TAG_PADDING_METHOD, value->padding_method);
13523 }
13524
13525 if(kmip_is_tag_next(ctx, KMIP_TAG_HASHING_ALGORITHM))
13526 {
13527 result = kmip_decode_enum(ctx, KMIP_TAG_HASHING_ALGORITHM, &value->hashing_algorithm);
13528 CHECK_RESULT(ctx, result);
13529 CHECK_ENUM(ctx, KMIP_TAG_HASHING_ALGORITHM, value->hashing_algorithm);
13530 }
13531
13532 if(kmip_is_tag_next(ctx, KMIP_TAG_KEY_ROLE_TYPE))
13533 {
13534 result = kmip_decode_enum(ctx, KMIP_TAG_KEY_ROLE_TYPE, &value->key_role_type);
13535 CHECK_RESULT(ctx, result);
13536 CHECK_ENUM(ctx, KMIP_TAG_KEY_ROLE_TYPE, value->key_role_type);
13537 }
13538
13539 if(ctx->version >= KMIP_1_2)
13540 {
13541 if(kmip_is_tag_next(ctx, KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM))
13542 {
13543 result = kmip_decode_enum(ctx, KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM, &value->digital_signature_algorithm);
13544 CHECK_RESULT(ctx, result);
13545 CHECK_ENUM(ctx, KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM, value->digital_signature_algorithm);
13546 }
13547
13548 if(kmip_is_tag_next(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM))
13549 {
13550 result = kmip_decode_enum(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM, &value->cryptographic_algorithm);
13551 CHECK_RESULT(ctx, result);
13552 CHECK_ENUM(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM, value->cryptographic_algorithm);
13553 }
13554
13555 if(kmip_is_tag_next(ctx, KMIP_TAG_RANDOM_IV))
13556 {
13557 result = kmip_decode_bool(ctx, KMIP_TAG_RANDOM_IV, &value->random_iv);
13558 CHECK_RESULT(ctx, result);
13559 }
13560
13561 if(kmip_is_tag_next(ctx, KMIP_TAG_IV_LENGTH))
13562 {
13563 result = kmip_decode_integer(ctx, KMIP_TAG_IV_LENGTH, &value->iv_length);
13564 CHECK_RESULT(ctx, result);
13565 }
13566
13567 if(kmip_is_tag_next(ctx, KMIP_TAG_TAG_LENGTH))
13568 {
13569 result = kmip_decode_integer(ctx, KMIP_TAG_TAG_LENGTH, &value->tag_length);
13570 CHECK_RESULT(ctx, result);
13571 }
13572
13573 if(kmip_is_tag_next(ctx, KMIP_TAG_FIXED_FIELD_LENGTH))
13574 {
13575 result = kmip_decode_integer(ctx, KMIP_TAG_FIXED_FIELD_LENGTH, &value->fixed_field_length);
13576 CHECK_RESULT(ctx, result);
13577 }
13578
13579 if(kmip_is_tag_next(ctx, KMIP_TAG_INVOCATION_FIELD_LENGTH))
13580 {
13581 result = kmip_decode_integer(ctx, KMIP_TAG_INVOCATION_FIELD_LENGTH, &value->invocation_field_length);
13582 CHECK_RESULT(ctx, result);
13583 }
13584
13585 if(kmip_is_tag_next(ctx, KMIP_TAG_COUNTER_LENGTH))
13586 {
13587 result = kmip_decode_integer(ctx, KMIP_TAG_COUNTER_LENGTH, &value->counter_length);
13588 CHECK_RESULT(ctx, result);
13589 }
13590
13591 if(kmip_is_tag_next(ctx, KMIP_TAG_INITIAL_COUNTER_VALUE))
13592 {
13593 result = kmip_decode_integer(ctx, KMIP_TAG_INITIAL_COUNTER_VALUE, &value->initial_counter_value);
13594 CHECK_RESULT(ctx, result);
13595 }
13596 }
13597
13598 if(ctx->version >= KMIP_1_4)
13599 {
13600 if(kmip_is_tag_next(ctx, KMIP_TAG_SALT_LENGTH))
13601 {
13602 result = kmip_decode_integer(ctx, KMIP_TAG_SALT_LENGTH, &value->salt_length);
13603 CHECK_RESULT(ctx, result);
13604 }
13605
13606 if(kmip_is_tag_next(ctx, KMIP_TAG_MASK_GENERATOR))
13607 {
13608 result = kmip_decode_enum(ctx, KMIP_TAG_MASK_GENERATOR, &value->mask_generator);
13609 CHECK_RESULT(ctx, result);
13610 CHECK_ENUM(ctx, KMIP_TAG_MASK_GENERATOR, value->mask_generator);
13611 }
13612
13613 if(kmip_is_tag_next(ctx, KMIP_TAG_MASK_GENERATOR_HASHING_ALGORITHM))
13614 {
13615 result = kmip_decode_enum(ctx, KMIP_TAG_MASK_GENERATOR_HASHING_ALGORITHM, &value->mask_generator_hashing_algorithm);
13616 CHECK_RESULT(ctx, result);
13617 CHECK_ENUM(ctx, KMIP_TAG_HASHING_ALGORITHM, value->mask_generator_hashing_algorithm);
13618 }
13619
13620 if(kmip_is_tag_next(ctx, KMIP_TAG_P_SOURCE))
13621 {
13622 value->p_source = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
13623 CHECK_NEW_MEMORY(ctx, value->p_source, sizeof(ByteString), "P Source byte string");
13624
13625 result = kmip_decode_byte_string(ctx, KMIP_TAG_P_SOURCE, value->p_source);
13626 CHECK_RESULT(ctx, result);
13627 }
13628
13629 if(kmip_is_tag_next(ctx, KMIP_TAG_TRAILER_FIELD))
13630 {
13631 result = kmip_decode_integer(ctx, KMIP_TAG_TRAILER_FIELD, &value->trailer_field);
13632 CHECK_RESULT(ctx, result);
13633 }
13634 }
13635
13636 return(KMIP_OK);
13637 }
13638
13639 int
13640 kmip_decode_encryption_key_information(KMIP *ctx, EncryptionKeyInformation *value)
13641 {
13642 CHECK_BUFFER_FULL(ctx, 8);
13643
13644 int result = 0;
13645 int32 tag_type = 0;
13646 uint32 length = 0;
13647
13648 kmip_decode_int32_be(ctx, &tag_type);
13649 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_ENCRYPTION_KEY_INFORMATION, KMIP_TYPE_STRUCTURE);
13650
13651 kmip_decode_length(ctx, &length);
13652 CHECK_BUFFER_FULL(ctx, length);
13653
13654 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
13655 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
13656
13657 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
13658 CHECK_RESULT(ctx, result);
13659
13660 if(kmip_is_tag_next(ctx, KMIP_TAG_CRYPTOGRAPHIC_PARAMETERS))
13661 {
13662 value->cryptographic_parameters = ctx->calloc_func(ctx->state, 1, sizeof(CryptographicParameters));
13663 CHECK_NEW_MEMORY(ctx, value->cryptographic_parameters, sizeof(CryptographicParameters), "CryptographicParameters structure");
13664
13665 result = kmip_decode_cryptographic_parameters(ctx, value->cryptographic_parameters);
13666 CHECK_RESULT(ctx, result);
13667 }
13668
13669 return(KMIP_OK);
13670 }
13671
13672 int
13673 kmip_decode_mac_signature_key_information(KMIP *ctx, MACSignatureKeyInformation *value)
13674 {
13675 CHECK_BUFFER_FULL(ctx, 8);
13676
13677 int result = 0;
13678 int32 tag_type = 0;
13679 uint32 length = 0;
13680
13681 kmip_decode_int32_be(ctx, &tag_type);
13682 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_MAC_SIGNATURE_KEY_INFORMATION, KMIP_TYPE_STRUCTURE);
13683
13684 kmip_decode_length(ctx, &length);
13685 CHECK_BUFFER_FULL(ctx, length);
13686
13687 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
13688 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
13689
13690 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
13691 CHECK_RESULT(ctx, result);
13692
13693 if(kmip_is_tag_next(ctx, KMIP_TAG_CRYPTOGRAPHIC_PARAMETERS))
13694 {
13695 value->cryptographic_parameters = ctx->calloc_func(ctx->state, 1, sizeof(CryptographicParameters));
13696 CHECK_NEW_MEMORY(ctx, value->cryptographic_parameters, sizeof(CryptographicParameters), "CryptographicParameters structure");
13697
13698 result = kmip_decode_cryptographic_parameters(ctx, value->cryptographic_parameters);
13699 CHECK_RESULT(ctx, result);
13700 }
13701
13702 return(KMIP_OK);
13703 }
13704
13705
13706 int
13707 kmip_decode_key_wrapping_data(KMIP *ctx, KeyWrappingData *value)
13708 {
13709 CHECK_BUFFER_FULL(ctx, 8);
13710
13711 int result = 0;
13712 int32 tag_type = 0;
13713 uint32 length = 0;
13714
13715 kmip_decode_int32_be(ctx, &tag_type);
13716 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_KEY_WRAPPING_DATA, KMIP_TYPE_STRUCTURE);
13717
13718 kmip_decode_length(ctx, &length);
13719 CHECK_BUFFER_FULL(ctx, length);
13720
13721 result = kmip_decode_enum(ctx, KMIP_TAG_WRAPPING_METHOD, &value->wrapping_method);
13722 CHECK_RESULT(ctx, result);
13723 CHECK_ENUM(ctx, KMIP_TAG_WRAPPING_METHOD, value->wrapping_method);
13724
13725 if(kmip_is_tag_next(ctx, KMIP_TAG_ENCRYPTION_KEY_INFORMATION))
13726 {
13727 value->encryption_key_info = ctx->calloc_func(ctx->state, 1, sizeof(EncryptionKeyInformation));
13728 CHECK_NEW_MEMORY(ctx, value->encryption_key_info, sizeof(EncryptionKeyInformation), "EncryptionKeyInformation structure");
13729
13730 result = kmip_decode_encryption_key_information(ctx, value->encryption_key_info);
13731 CHECK_RESULT(ctx, result);
13732 }
13733
13734 if(kmip_is_tag_next(ctx, KMIP_TAG_MAC_SIGNATURE_KEY_INFORMATION))
13735 {
13736 value->mac_signature_key_info = ctx->calloc_func(ctx->state, 1, sizeof(MACSignatureKeyInformation));
13737 CHECK_NEW_MEMORY(ctx, value->mac_signature_key_info, sizeof(MACSignatureKeyInformation), "MAC/SignatureKeyInformation structure");
13738
13739 result = kmip_decode_mac_signature_key_information(ctx, value->mac_signature_key_info);
13740 CHECK_RESULT(ctx, result);
13741 }
13742
13743 if(kmip_is_tag_next(ctx, KMIP_TAG_MAC_SIGNATURE))
13744 {
13745 value->mac_signature = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
13746 CHECK_NEW_MEMORY(ctx, value->mac_signature, sizeof(ByteString), "MAC/Signature byte string");
13747
13748 result = kmip_decode_byte_string(ctx, KMIP_TAG_MAC_SIGNATURE, value->mac_signature);
13749 CHECK_RESULT(ctx, result);
13750 }
13751
13752 if(kmip_is_tag_next(ctx, KMIP_TAG_IV_COUNTER_NONCE))
13753 {
13754 value->iv_counter_nonce = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
13755 CHECK_NEW_MEMORY(ctx, value->iv_counter_nonce, sizeof(ByteString), "IV/Counter/Nonce byte string");
13756
13757 result = kmip_decode_byte_string(ctx, KMIP_TAG_IV_COUNTER_NONCE, value->iv_counter_nonce);
13758 CHECK_RESULT(ctx, result);
13759 }
13760
13761 if(ctx->version >= KMIP_1_1)
13762 {
13763 if(kmip_is_tag_next(ctx, KMIP_TAG_ENCODING_OPTION))
13764 {
13765 result = kmip_decode_enum(ctx, KMIP_TAG_ENCODING_OPTION, &value->encoding_option);
13766 CHECK_RESULT(ctx, result);
13767 CHECK_ENUM(ctx, KMIP_TAG_ENCODING_OPTION, value->encoding_option);
13768 }
13769 }
13770
13771 return(KMIP_OK);
13772 }
13773
13774 int
13775 kmip_decode_key_block(KMIP *ctx, KeyBlock *value)
13776 {
13777 CHECK_BUFFER_FULL(ctx, 8);
13778
13779 int result = 0;
13780 int32 tag_type = 0;
13781 uint32 length = 0;
13782
13783 kmip_decode_int32_be(ctx, &tag_type);
13784 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_KEY_BLOCK, KMIP_TYPE_STRUCTURE);
13785
13786 kmip_decode_length(ctx, &length);
13787 CHECK_BUFFER_FULL(ctx, length);
13788
13789 result = kmip_decode_enum(ctx, KMIP_TAG_KEY_FORMAT_TYPE, &value->key_format_type);
13790 CHECK_RESULT(ctx, result);
13791 CHECK_ENUM(ctx, KMIP_TAG_KEY_FORMAT_TYPE, value->key_format_type);
13792
13793 if(kmip_is_tag_next(ctx, KMIP_TAG_KEY_COMPRESSION_TYPE))
13794 {
13795 result = kmip_decode_enum(ctx, KMIP_TAG_KEY_COMPRESSION_TYPE, &value->key_compression_type);
13796 CHECK_RESULT(ctx, result);
13797 CHECK_ENUM(ctx, KMIP_TAG_KEY_COMPRESSION_TYPE, value->key_compression_type);
13798 }
13799
13800 if(kmip_is_tag_type_next(ctx, KMIP_TAG_KEY_VALUE, KMIP_TYPE_BYTE_STRING))
13801 {
13802 value->key_value_type = KMIP_TYPE_BYTE_STRING;
13803 value->key_value = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
13804 CHECK_NEW_MEMORY(ctx, value->key_value, sizeof(ByteString), "KeyValue byte string");
13805
13806 result = kmip_decode_byte_string(ctx, KMIP_TAG_KEY_VALUE, (ByteString *)value->key_value);
13807 }
13808 else
13809 {
13810 value->key_value_type = KMIP_TYPE_STRUCTURE;
13811 value->key_value = ctx->calloc_func(ctx->state, 1, sizeof(KeyValue));
13812 CHECK_NEW_MEMORY(ctx, value->key_value, sizeof(KeyValue), "KeyValue structure");
13813
13814 result = kmip_decode_key_value(ctx, value->key_format_type, (KeyValue *)value->key_value);
13815 }
13816 CHECK_RESULT(ctx, result);
13817
13818 if(kmip_is_tag_next(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM))
13819 {
13820 result = kmip_decode_enum(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM, &value->cryptographic_algorithm);
13821 CHECK_RESULT(ctx, result);
13822 CHECK_ENUM(ctx, KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM, value->cryptographic_algorithm);
13823 }
13824
13825 if(kmip_is_tag_next(ctx, KMIP_TAG_CRYPTOGRAPHIC_LENGTH))
13826 {
13827 result = kmip_decode_integer(ctx, KMIP_TAG_CRYPTOGRAPHIC_LENGTH, &value->cryptographic_length);
13828 CHECK_RESULT(ctx, result);
13829 }
13830
13831 if(kmip_is_tag_next(ctx, KMIP_TAG_KEY_WRAPPING_DATA))
13832 {
13833 value->key_wrapping_data = ctx->calloc_func(ctx->state, 1, sizeof(KeyWrappingData));
13834 CHECK_NEW_MEMORY(ctx, value->key_wrapping_data, sizeof(KeyWrappingData), "KeyWrappingData structure");
13835
13836 result = kmip_decode_key_wrapping_data(ctx, value->key_wrapping_data);
13837 CHECK_RESULT(ctx, result);
13838 }
13839
13840 return(KMIP_OK);
13841 }
13842
13843 int
13844 kmip_decode_symmetric_key(KMIP *ctx, SymmetricKey *value)
13845 {
13846 CHECK_BUFFER_FULL(ctx, 8);
13847
13848 int result = 0;
13849 int32 tag_type = 0;
13850 uint32 length = 0;
13851
13852 kmip_decode_int32_be(ctx, &tag_type);
13853 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_SYMMETRIC_KEY, KMIP_TYPE_STRUCTURE);
13854
13855 kmip_decode_length(ctx, &length);
13856 CHECK_BUFFER_FULL(ctx, length);
13857
13858 value->key_block = ctx->calloc_func(ctx->state, 1, sizeof(KeyBlock));
13859 CHECK_NEW_MEMORY(ctx, value->key_block, sizeof(KeyBlock), "KeyBlock structure");
13860
13861 result = kmip_decode_key_block(ctx, value->key_block);
13862 CHECK_RESULT(ctx, result);
13863
13864 return(KMIP_OK);
13865 }
13866
13867 int
13868 kmip_decode_public_key(KMIP *ctx, PublicKey *value)
13869 {
13870 CHECK_BUFFER_FULL(ctx, 8);
13871
13872 int result = 0;
13873 int32 tag_type = 0;
13874 uint32 length = 0;
13875
13876 kmip_decode_int32_be(ctx, &tag_type);
13877 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_PUBLIC_KEY, KMIP_TYPE_STRUCTURE);
13878
13879 kmip_decode_length(ctx, &length);
13880 CHECK_BUFFER_FULL(ctx, length);
13881
13882 value->key_block = ctx->calloc_func(ctx->state, 1, sizeof(KeyBlock));
13883 CHECK_NEW_MEMORY(ctx, value->key_block, sizeof(KeyBlock), "KeyBlock structure");
13884
13885 result = kmip_decode_key_block(ctx, value->key_block);
13886 CHECK_RESULT(ctx, result);
13887
13888 return(KMIP_OK);
13889 }
13890
13891 int
13892 kmip_decode_private_key(KMIP *ctx, PrivateKey *value)
13893 {
13894 CHECK_BUFFER_FULL(ctx, 8);
13895
13896 int result = 0;
13897 int32 tag_type = 0;
13898 uint32 length = 0;
13899
13900 kmip_decode_int32_be(ctx, &tag_type);
13901 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_PRIVATE_KEY, KMIP_TYPE_STRUCTURE);
13902
13903 kmip_decode_length(ctx, &length);
13904 CHECK_BUFFER_FULL(ctx, length);
13905
13906 value->key_block = ctx->calloc_func(ctx->state, 1, sizeof(KeyBlock));
13907 CHECK_NEW_MEMORY(ctx, value->key_block, sizeof(KeyBlock), "KeyBlock structure");
13908
13909 result = kmip_decode_key_block(ctx, value->key_block);
13910 CHECK_RESULT(ctx, result);
13911
13912 return(KMIP_OK);
13913 }
13914
13915 int
13916 kmip_decode_key_wrapping_specification(KMIP *ctx, KeyWrappingSpecification *value)
13917 {
13918 CHECK_BUFFER_FULL(ctx, 8);
13919
13920 int result = 0;
13921 int32 tag_type = 0;
13922 uint32 length = 0;
13923
13924 kmip_decode_int32_be(ctx, &tag_type);
13925 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_KEY_WRAPPING_SPECIFICATION, KMIP_TYPE_STRUCTURE);
13926
13927 kmip_decode_length(ctx, &length);
13928 CHECK_BUFFER_FULL(ctx, length);
13929
13930 result = kmip_decode_enum(ctx, KMIP_TAG_WRAPPING_METHOD, &value->wrapping_method);
13931 CHECK_RESULT(ctx, result);
13932 CHECK_ENUM(ctx, KMIP_TAG_WRAPPING_METHOD, value->wrapping_method);
13933
13934 if(kmip_is_tag_next(ctx, KMIP_TAG_ENCRYPTION_KEY_INFORMATION))
13935 {
13936 value->encryption_key_info = ctx->calloc_func(ctx->state, 1, sizeof(EncryptionKeyInformation));
13937 CHECK_NEW_MEMORY(ctx, value->encryption_key_info, sizeof(EncryptionKeyInformation), "EncryptionKeyInformation structure");
13938 result = kmip_decode_encryption_key_information(ctx, value->encryption_key_info);
13939 CHECK_RESULT(ctx, result);
13940 }
13941
13942 if(kmip_is_tag_next(ctx, KMIP_TAG_MAC_SIGNATURE_KEY_INFORMATION))
13943 {
13944 value->mac_signature_key_info = ctx->calloc_func(ctx->state, 1, sizeof(MACSignatureKeyInformation));
13945 CHECK_NEW_MEMORY(ctx, value->mac_signature_key_info, sizeof(MACSignatureKeyInformation), "MACSignatureKeyInformation structure");
13946 result = kmip_decode_mac_signature_key_information(ctx, value->mac_signature_key_info);
13947 CHECK_RESULT(ctx, result);
13948 }
13949
13950 value->attribute_name_count = kmip_get_num_items_next(ctx, KMIP_TAG_ATTRIBUTE_NAME);
13951 if(value->attribute_name_count > 0)
13952 {
13953 value->attribute_names = ctx->calloc_func(ctx->state, value->attribute_name_count, sizeof(TextString));
13954 CHECK_NEW_MEMORY(ctx, value->attribute_names, value->attribute_name_count * sizeof(TextString), "sequence of AttributeName text strings");
13955
13956 for(size_t i = 0; i < value->attribute_name_count; i++)
13957 {
13958 result = kmip_decode_text_string(ctx, KMIP_TAG_ATTRIBUTE_NAME, &value->attribute_names[i]);
13959 CHECK_RESULT(ctx, result);
13960 }
13961 }
13962
13963 if(ctx->version >= KMIP_1_1)
13964 {
13965 result = kmip_decode_enum(ctx, KMIP_TAG_ENCODING_OPTION, &value->encoding_option);
13966 CHECK_RESULT(ctx, result);
13967 CHECK_ENUM(ctx, KMIP_TAG_ENCODING_OPTION, value->encoding_option);
13968 }
13969
13970 return(KMIP_OK);
13971 }
13972
13973 int
13974 kmip_decode_create_request_payload(KMIP *ctx, CreateRequestPayload *value)
13975 {
13976 CHECK_DECODE_ARGS(ctx, value);
13977 CHECK_BUFFER_FULL(ctx, 8);
13978
13979 int result = 0;
13980 int32 tag_type = 0;
13981 uint32 length = 0;
13982
13983 kmip_decode_int32_be(ctx, &tag_type);
13984 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE);
13985
13986 kmip_decode_length(ctx, &length);
13987 CHECK_BUFFER_FULL(ctx, length);
13988
13989 result = kmip_decode_enum(ctx, KMIP_TAG_OBJECT_TYPE, &value->object_type);
13990 CHECK_RESULT(ctx, result);
13991 CHECK_ENUM(ctx, KMIP_TAG_OBJECT_TYPE, value->object_type);
13992
13993 if(ctx->version < KMIP_2_0)
13994 {
13995 value->template_attribute = ctx->calloc_func(ctx->state, 1, sizeof(TemplateAttribute));
13996 if(value->template_attribute == NULL)
13997 {
13998 HANDLE_FAILED_ALLOC(ctx, sizeof(TemplateAttribute), "TemplateAttribute");
13999 }
14000 result = kmip_decode_template_attribute(ctx, value->template_attribute);
14001 if(result != KMIP_OK)
14002 {
14003 kmip_free_template_attribute(ctx, value->template_attribute);
14004 ctx->free_func(ctx, value->template_attribute);
14005 value->template_attribute = NULL;
14006 HANDLE_FAILURE(ctx, result);
14007 }
14008 }
14009 else
14010 {
14011 value->attributes = ctx->calloc_func(ctx->state, 1, sizeof(Attributes));
14012 if(value->attributes == NULL)
14013 {
14014 HANDLE_FAILED_ALLOC(ctx, sizeof(Attributes), "Attributes");
14015 }
14016 result = kmip_decode_attributes(ctx, value->attributes);
14017 if(result != KMIP_OK)
14018 {
14019 kmip_free_attributes(ctx, value->attributes);
14020 ctx->free_func(ctx, value->attributes);
14021 value->attributes = NULL;
14022
14023 HANDLE_FAILURE(ctx, result);
14024 }
14025
14026 if(kmip_is_tag_next(ctx, KMIP_TAG_PROTECTION_STORAGE_MASKS))
14027 {
14028 value->protection_storage_masks = ctx->calloc_func(ctx->state, 1, sizeof(ProtectionStorageMasks));
14029 if(value->protection_storage_masks == NULL)
14030 {
14031 kmip_free_attributes(ctx, value->attributes);
14032 ctx->free_func(ctx, value->attributes);
14033 value->attributes = NULL;
14034
14035 HANDLE_FAILED_ALLOC(ctx, sizeof(ProtectionStorageMasks), "ProtectionStorageMasks");
14036 }
14037 result = kmip_decode_protection_storage_masks(ctx, value->protection_storage_masks);
14038 if(result != KMIP_OK)
14039 {
14040 kmip_free_attributes(ctx, value->attributes);
14041 kmip_free_protection_storage_masks(ctx, value->protection_storage_masks);
14042 ctx->free_func(ctx, value->attributes);
14043 ctx->free_func(ctx, value->protection_storage_masks);
14044 value->attributes = NULL;
14045 value->protection_storage_masks = NULL;
14046
14047 HANDLE_FAILURE(ctx, result);
14048 }
14049 }
14050 }
14051
14052 return(KMIP_OK);
14053 }
14054
14055 int
14056 kmip_decode_create_response_payload(KMIP *ctx, CreateResponsePayload *value)
14057 {
14058 CHECK_DECODE_ARGS(ctx, value);
14059 CHECK_BUFFER_FULL(ctx, 8);
14060
14061 int result = 0;
14062 int32 tag_type = 0;
14063 uint32 length = 0;
14064
14065 kmip_decode_int32_be(ctx, &tag_type);
14066 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE);
14067
14068 kmip_decode_length(ctx, &length);
14069 CHECK_BUFFER_FULL(ctx, length);
14070
14071 result = kmip_decode_enum(ctx, KMIP_TAG_OBJECT_TYPE, &value->object_type);
14072 CHECK_RESULT(ctx, result);
14073 CHECK_ENUM(ctx, KMIP_TAG_OBJECT_TYPE, value->object_type);
14074
14075 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14076 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
14077
14078 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
14079 CHECK_RESULT(ctx, result);
14080
14081 if(ctx->version < KMIP_2_0)
14082 {
14083 if(kmip_is_tag_next(ctx, KMIP_TAG_TEMPLATE_ATTRIBUTE))
14084 {
14085 value->template_attribute = ctx->calloc_func(ctx->state, 1, sizeof(TemplateAttribute));
14086 CHECK_NEW_MEMORY(ctx, value->template_attribute, sizeof(TemplateAttribute), "TemplateAttribute structure");
14087
14088 result = kmip_decode_template_attribute(ctx, value->template_attribute);
14089 CHECK_RESULT(ctx, result);
14090 }
14091 }
14092
14093 return(KMIP_OK);
14094 }
14095
14096 int
14097 kmip_decode_register_request_payload(KMIP *ctx, RegisterRequestPayload *value)
14098 {
14099 CHECK_DECODE_ARGS(ctx, value);
14100 CHECK_BUFFER_FULL(ctx, 8);
14101
14102 int result = 0;
14103 int32 tag_type = 0;
14104 uint32 length = 0;
14105
14106 kmip_decode_int32_be(ctx, &tag_type);
14107 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE);
14108
14109 kmip_decode_length(ctx, &length);
14110 CHECK_BUFFER_FULL(ctx, length);
14111
14112 result = kmip_decode_enum(ctx, KMIP_TAG_OBJECT_TYPE, &value->object_type);
14113 CHECK_RESULT(ctx, result);
14114 CHECK_ENUM(ctx, KMIP_TAG_OBJECT_TYPE, value->object_type);
14115
14116 if(ctx->version < KMIP_2_0)
14117 {
14118 value->template_attribute = ctx->calloc_func(ctx->state, 1, sizeof(TemplateAttribute));
14119 if(value->template_attribute == NULL)
14120 {
14121 HANDLE_FAILED_ALLOC(ctx, sizeof(TemplateAttribute), "TemplateAttribute");
14122 }
14123 result = kmip_decode_template_attribute(ctx, value->template_attribute);
14124 if(result != KMIP_OK)
14125 {
14126 kmip_free_template_attribute(ctx, value->template_attribute);
14127 ctx->free_func(ctx, value->template_attribute);
14128 value->template_attribute = NULL;
14129 HANDLE_FAILURE(ctx, result);
14130 }
14131 }
14132 else
14133 {
14134 value->attributes = ctx->calloc_func(ctx->state, 1, sizeof(Attributes));
14135 if(value->attributes == NULL)
14136 {
14137 HANDLE_FAILED_ALLOC(ctx, sizeof(Attributes), "Attributes");
14138 }
14139 result = kmip_decode_attributes(ctx, value->attributes);
14140 if(result != KMIP_OK)
14141 {
14142 kmip_free_attributes(ctx, value->attributes);
14143 ctx->free_func(ctx, value->attributes);
14144 value->attributes = NULL;
14145
14146 HANDLE_FAILURE(ctx, result);
14147 }
14148
14149 if(kmip_is_tag_next(ctx, KMIP_TAG_PROTECTION_STORAGE_MASKS))
14150 {
14151 value->protection_storage_masks = ctx->calloc_func(ctx->state, 1, sizeof(ProtectionStorageMasks));
14152 if(value->protection_storage_masks == NULL)
14153 {
14154 kmip_free_attributes(ctx, value->attributes);
14155 ctx->free_func(ctx, value->attributes);
14156 value->attributes = NULL;
14157
14158 HANDLE_FAILED_ALLOC(ctx, sizeof(ProtectionStorageMasks), "ProtectionStorageMasks");
14159 }
14160 result = kmip_decode_protection_storage_masks(ctx, value->protection_storage_masks);
14161 if(result != KMIP_OK)
14162 {
14163 kmip_free_attributes(ctx, value->attributes);
14164 kmip_free_protection_storage_masks(ctx, value->protection_storage_masks);
14165 ctx->free_func(ctx, value->attributes);
14166 ctx->free_func(ctx, value->protection_storage_masks);
14167 value->attributes = NULL;
14168 value->protection_storage_masks = NULL;
14169
14170 HANDLE_FAILURE(ctx, result);
14171 }
14172 }
14173 }
14174
14175 result = kmip_decode_symmetric_key(ctx, &value->object);
14176 if (result != KMIP_OK)
14177 {
14178 kmip_free_attributes(ctx, value->attributes);
14179 kmip_free_protection_storage_masks(ctx, value->protection_storage_masks);
14180 ctx->free_func(ctx, value->attributes);
14181 ctx->free_func(ctx, value->protection_storage_masks);
14182 value->attributes = NULL;
14183 value->protection_storage_masks = NULL;
14184
14185 HANDLE_FAILURE(ctx, result);
14186 }
14187 //value->object = ctx->calloc_func(ctx->state, 1, sizeof(SymmetricKey));
14188 //CHECK_NEW_MEMORY(ctx, value->object, sizeof(SymmetricKey), "SymmetricKey structure");
14189 result = kmip_decode_symmetric_key(ctx, &value->object);
14190 CHECK_RESULT(ctx, result);
14191
14192 return(KMIP_OK);
14193 }
14194
14195 int
14196 kmip_decode_register_response_payload(KMIP *ctx, RegisterResponsePayload *value)
14197 {
14198 CHECK_DECODE_ARGS(ctx, value);
14199 CHECK_BUFFER_FULL(ctx, 8);
14200
14201 int result = 0;
14202 int32 tag_type = 0;
14203 uint32 length = 0;
14204
14205 kmip_decode_int32_be(ctx, &tag_type);
14206 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE);
14207
14208 kmip_decode_length(ctx, &length);
14209 CHECK_BUFFER_FULL(ctx, length);
14210
14211 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14212 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
14213
14214 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
14215 CHECK_RESULT(ctx, result);
14216
14217 if(ctx->version < KMIP_2_0)
14218 {
14219 if(kmip_is_tag_next(ctx, KMIP_TAG_TEMPLATE_ATTRIBUTE))
14220 {
14221 value->template_attribute = ctx->calloc_func(ctx->state, 1, sizeof(TemplateAttribute));
14222 CHECK_NEW_MEMORY(ctx, value->template_attribute, sizeof(TemplateAttribute), "TemplateAttribute structure");
14223
14224 result = kmip_decode_template_attribute(ctx, value->template_attribute);
14225 CHECK_RESULT(ctx, result);
14226 }
14227 }
14228
14229 return(KMIP_OK);
14230 }
14231
14232 int
14233 kmip_decode_get_request_payload(KMIP *ctx, GetRequestPayload *value)
14234 {
14235 CHECK_BUFFER_FULL(ctx, 8);
14236
14237 int result = 0;
14238 int32 tag_type = 0;
14239 uint32 length = 0;
14240
14241 kmip_decode_int32_be(ctx, &tag_type);
14242 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE);
14243
14244 kmip_decode_length(ctx, &length);
14245 CHECK_BUFFER_FULL(ctx, length);
14246
14247 if(kmip_is_tag_next(ctx, KMIP_TAG_UNIQUE_IDENTIFIER))
14248 {
14249 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14250 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
14251 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
14252 CHECK_RESULT(ctx, result);
14253 }
14254
14255 if(kmip_is_tag_next(ctx, KMIP_TAG_KEY_FORMAT_TYPE))
14256 {
14257 result = kmip_decode_enum(ctx, KMIP_TAG_KEY_FORMAT_TYPE, &value->key_format_type);
14258 CHECK_RESULT(ctx, result);
14259 CHECK_ENUM(ctx, KMIP_TAG_KEY_FORMAT_TYPE, value->key_format_type);
14260 }
14261
14262 if(ctx->version >= KMIP_1_4)
14263 {
14264 if(kmip_is_tag_next(ctx, KMIP_TAG_KEY_WRAP_TYPE))
14265 {
14266 result = kmip_decode_enum(ctx, KMIP_TAG_KEY_WRAP_TYPE, &value->key_wrap_type);
14267 CHECK_RESULT(ctx, result);
14268 CHECK_ENUM(ctx, KMIP_TAG_KEY_WRAP_TYPE, value->key_wrap_type);
14269 }
14270 }
14271
14272 if(kmip_is_tag_next(ctx, KMIP_TAG_KEY_COMPRESSION_TYPE))
14273 {
14274 result = kmip_decode_enum(ctx, KMIP_TAG_KEY_COMPRESSION_TYPE, &value->key_compression_type);
14275 CHECK_RESULT(ctx, result);
14276 CHECK_ENUM(ctx, KMIP_TAG_KEY_COMPRESSION_TYPE, value->key_compression_type);
14277 }
14278
14279 if(kmip_is_tag_next(ctx, KMIP_TAG_KEY_WRAPPING_SPECIFICATION))
14280 {
14281 value->key_wrapping_spec = ctx->calloc_func(ctx->state, 1, sizeof(KeyWrappingSpecification));
14282 CHECK_NEW_MEMORY(ctx, value->key_wrapping_spec, sizeof(KeyWrappingSpecification), "KeyWrappingSpecification structure");
14283 result = kmip_decode_key_wrapping_specification(ctx, value->key_wrapping_spec);
14284 CHECK_RESULT(ctx, result);
14285 }
14286
14287 return(KMIP_OK);
14288 }
14289
14290 int
14291 kmip_decode_get_response_payload(KMIP *ctx, GetResponsePayload *value)
14292 {
14293 CHECK_BUFFER_FULL(ctx, 8);
14294
14295 int result = 0;
14296 int32 tag_type = 0;
14297 uint32 length = 0;
14298
14299 kmip_decode_int32_be(ctx, &tag_type);
14300 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE);
14301
14302 kmip_decode_length(ctx, &length);
14303 CHECK_BUFFER_FULL(ctx, length);
14304
14305 result = kmip_decode_enum(ctx, KMIP_TAG_OBJECT_TYPE, &value->object_type);
14306 CHECK_RESULT(ctx, result);
14307 CHECK_ENUM(ctx, KMIP_TAG_OBJECT_TYPE, value->object_type);
14308
14309 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14310 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
14311
14312 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
14313 CHECK_RESULT(ctx, result);
14314
14315 switch(value->object_type)
14316 {
14317 case KMIP_OBJTYPE_SYMMETRIC_KEY:
14318 value->object = ctx->calloc_func(ctx->state, 1, sizeof(SymmetricKey));
14319 CHECK_NEW_MEMORY(ctx, value->object, sizeof(SymmetricKey), "SymmetricKey structure");
14320 result = kmip_decode_symmetric_key(ctx, (SymmetricKey*)value->object);
14321 CHECK_RESULT(ctx, result);
14322 break;
14323
14324 case KMIP_OBJTYPE_PUBLIC_KEY:
14325 value->object = ctx->calloc_func(ctx->state, 1, sizeof(PublicKey));
14326 CHECK_NEW_MEMORY(ctx, value->object, sizeof(PublicKey), "PublicKey structure");
14327 result = kmip_decode_public_key(ctx, (PublicKey*)value->object);
14328 CHECK_RESULT(ctx, result);
14329 break;
14330
14331 case KMIP_OBJTYPE_PRIVATE_KEY:
14332 value->object = ctx->calloc_func(ctx->state, 1, sizeof(PrivateKey));
14333 CHECK_NEW_MEMORY(ctx, value->object, sizeof(PrivateKey), "PrivateKey structure");
14334 result = kmip_decode_private_key(ctx, (PrivateKey*)value->object);
14335 CHECK_RESULT(ctx, result);
14336 break;
14337
14338 default:
14339 kmip_push_error_frame(ctx, __func__, __LINE__);
14340 return(KMIP_NOT_IMPLEMENTED);
14341 break;
14342 };
14343
14344 return(KMIP_OK);
14345 }
14346
14347 int
14348 kmip_decode_get_attribute_request_payload(KMIP *ctx, GetAttributeRequestPayload *value)
14349 {
14350 CHECK_BUFFER_FULL(ctx, 8);
14351
14352 int result = 0;
14353 int32 tag_type = 0;
14354 uint32 length = 0;
14355
14356 kmip_decode_int32_be(ctx, &tag_type);
14357 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE);
14358
14359 kmip_decode_length(ctx, &length);
14360 CHECK_BUFFER_FULL(ctx, length);
14361
14362 if(kmip_is_tag_next(ctx, KMIP_TAG_UNIQUE_IDENTIFIER))
14363 {
14364 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14365 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
14366 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
14367 CHECK_RESULT(ctx, result);
14368 }
14369
14370 if(kmip_is_tag_next(ctx, KMIP_TAG_ATTRIBUTE_NAME))
14371 {
14372 value->attribute_name = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14373 CHECK_NEW_MEMORY(ctx, value->attribute_name, sizeof(TextString), "AttributeName text string");
14374 result = kmip_decode_text_string(ctx, KMIP_TAG_ATTRIBUTE_NAME, value->attribute_name);
14375 CHECK_RESULT(ctx, result);
14376 }
14377
14378 return(KMIP_OK);
14379 }
14380
14381 int
14382 kmip_decode_get_attribute_response_payload(KMIP *ctx, GetAttributeResponsePayload *value)
14383 {
14384 CHECK_BUFFER_FULL(ctx, 8);
14385
14386 int result = 0;
14387 int32 tag_type = 0;
14388 uint32 length = 0;
14389
14390
14391 kmip_decode_int32_be(ctx, &tag_type);
14392 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE);
14393
14394 kmip_decode_length(ctx, &length);
14395 CHECK_BUFFER_FULL(ctx, length);
14396
14397 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14398 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
14399
14400 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
14401 CHECK_RESULT(ctx, result);
14402
14403 value->attribute = ctx->calloc_func(ctx->state, 1, sizeof(Attribute));
14404 CHECK_NEW_MEMORY(ctx, value->attribute, sizeof(Attribute), "Attribute");
14405
14406 result = kmip_decode_attribute(ctx, value->attribute);
14407 CHECK_RESULT(ctx, result);
14408
14409 return(KMIP_OK);
14410 }
14411 int
14412 kmip_decode_destroy_request_payload(KMIP *ctx, DestroyRequestPayload *value)
14413 {
14414 CHECK_BUFFER_FULL(ctx, 8);
14415
14416 int result = 0;
14417 int32 tag_type = 0;
14418 uint32 length = 0;
14419
14420 kmip_decode_int32_be(ctx, &tag_type);
14421 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE);
14422
14423 kmip_decode_length(ctx, &length);
14424 CHECK_BUFFER_FULL(ctx, length);
14425
14426 if(kmip_is_tag_next(ctx, KMIP_TAG_UNIQUE_IDENTIFIER))
14427 {
14428 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14429 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
14430 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
14431 CHECK_RESULT(ctx, result);
14432 }
14433
14434 return(KMIP_OK);
14435 }
14436
14437 int
14438 kmip_decode_destroy_response_payload(KMIP *ctx, DestroyResponsePayload *value)
14439 {
14440 CHECK_BUFFER_FULL(ctx, 8);
14441
14442 int result = 0;
14443 int32 tag_type = 0;
14444 uint32 length = 0;
14445
14446 kmip_decode_int32_be(ctx, &tag_type);
14447 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE);
14448
14449 kmip_decode_length(ctx, &length);
14450 CHECK_BUFFER_FULL(ctx, length);
14451
14452 value->unique_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14453 CHECK_NEW_MEMORY(ctx, value->unique_identifier, sizeof(TextString), "UniqueIdentifier text string");
14454
14455 result = kmip_decode_text_string(ctx, KMIP_TAG_UNIQUE_IDENTIFIER, value->unique_identifier);
14456 CHECK_RESULT(ctx, result);
14457
14458 return(KMIP_OK);
14459 }
14460
14461 int
14462 kmip_decode_request_batch_item(KMIP *ctx, RequestBatchItem *value)
14463 {
14464 CHECK_DECODE_ARGS(ctx, value);
14465 CHECK_BUFFER_FULL(ctx, 8);
14466
14467 int result = 0;
14468 int32 tag_type = 0;
14469 uint32 length = 0;
14470
14471 kmip_decode_int32_be(ctx, &tag_type);
14472 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_BATCH_ITEM, KMIP_TYPE_STRUCTURE);
14473
14474 kmip_decode_length(ctx, &length);
14475 CHECK_BUFFER_FULL(ctx, length);
14476
14477 result = kmip_decode_enum(ctx, KMIP_TAG_OPERATION, &value->operation);
14478 CHECK_RESULT(ctx, result);
14479 CHECK_ENUM(ctx, KMIP_TAG_OPERATION, value->operation);
14480
14481 if(ctx->version >= KMIP_2_0)
14482 {
14483 if(kmip_is_tag_next(ctx, KMIP_TAG_EPHEMERAL))
14484 {
14485 result = kmip_decode_bool(ctx, KMIP_TAG_EPHEMERAL, &value->ephemeral);
14486 CHECK_RESULT(ctx, result);
14487 }
14488 }
14489
14490 if(kmip_is_tag_next(ctx, KMIP_TAG_UNIQUE_BATCH_ITEM_ID))
14491 {
14492 value->unique_batch_item_id = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
14493 CHECK_NEW_MEMORY(ctx, value->unique_batch_item_id, sizeof(ByteString), "UniqueBatchItemID byte string");
14494 result = kmip_decode_byte_string(ctx, KMIP_TAG_UNIQUE_BATCH_ITEM_ID, value->unique_batch_item_id);
14495 CHECK_RESULT(ctx, result);
14496 }
14497
14498 switch(value->operation)
14499 {
14500 case KMIP_OP_CREATE:
14501 value->request_payload = ctx->calloc_func(ctx->state, 1, sizeof(CreateRequestPayload));
14502 CHECK_NEW_MEMORY(ctx, value->request_payload, sizeof(CreateRequestPayload), "CreateRequestPayload structure");
14503 result = kmip_decode_create_request_payload(ctx, (CreateRequestPayload *)value->request_payload);
14504 break;
14505
14506 case KMIP_OP_REGISTER:
14507 value->request_payload = ctx->calloc_func(ctx->state, 1, sizeof(RegisterRequestPayload));
14508 CHECK_NEW_MEMORY(ctx, value->request_payload, sizeof(RegisterRequestPayload), "RegisterRequestPayload structure");
14509 result = kmip_decode_register_request_payload(ctx, (RegisterRequestPayload *)value->request_payload);
14510 break;
14511
14512 case KMIP_OP_GET:
14513 value->request_payload = ctx->calloc_func(ctx->state, 1, sizeof(GetRequestPayload));
14514 CHECK_NEW_MEMORY(ctx, value->request_payload, sizeof(GetRequestPayload), "GetRequestPayload structure");
14515 result = kmip_decode_get_request_payload(ctx, (GetRequestPayload*)value->request_payload);
14516 break;
14517
14518 case KMIP_OP_GET_ATTRIBUTES:
14519 value->request_payload = ctx->calloc_func(ctx->state, 1, sizeof(GetRequestPayload));
14520 CHECK_NEW_MEMORY(ctx, value->request_payload, sizeof(GetAttributeRequestPayload), "GetAttributeRequestPayload structure");
14521 result = kmip_decode_get_attribute_request_payload(ctx, (GetAttributeRequestPayload*)value->request_payload);
14522 break;
14523
14524 case KMIP_OP_DESTROY:
14525 value->request_payload = ctx->calloc_func(ctx->state, 1, sizeof(DestroyRequestPayload));
14526 CHECK_NEW_MEMORY(ctx, value->request_payload, sizeof(DestroyRequestPayload), "DestroyRequestPayload structure");
14527 result = kmip_decode_destroy_request_payload(ctx, (DestroyRequestPayload*)value->request_payload);
14528 break;
14529
14530 case KMIP_OP_QUERY:
14531 value->request_payload = ctx->calloc_func(ctx->state, 1, sizeof(QueryRequestPayload));
14532 CHECK_NEW_MEMORY(ctx, value->request_payload, sizeof(QueryRequestPayload), "QueryRequestPayload structure");
14533 result = kmip_decode_query_request_payload(ctx, (QueryRequestPayload*)value->request_payload);
14534 break;
14535
14536 case KMIP_OP_LOCATE:
14537 value->request_payload = ctx->calloc_func(ctx->state, 1, sizeof(LocateRequestPayload));
14538 CHECK_NEW_MEMORY(ctx, value->request_payload, sizeof(LocateRequestPayload), "LocateRequestPayload structure");
14539 result = kmip_decode_locate_request_payload(ctx, (LocateRequestPayload*)value->request_payload);
14540 break;
14541
14542 default:
14543 kmip_push_error_frame(ctx, __func__, __LINE__);
14544 return(KMIP_NOT_IMPLEMENTED);
14545 break;
14546 };
14547 CHECK_RESULT(ctx, result);
14548
14549 return(KMIP_OK);
14550 }
14551
14552 int
14553 kmip_decode_response_batch_item(KMIP *ctx, ResponseBatchItem *value)
14554 {
14555 CHECK_BUFFER_FULL(ctx, 8);
14556
14557 int result = 0;
14558 int32 tag_type = 0;
14559 uint32 length = 0;
14560
14561 kmip_decode_int32_be(ctx, &tag_type);
14562 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_BATCH_ITEM, KMIP_TYPE_STRUCTURE);
14563
14564 kmip_decode_length(ctx, &length);
14565 CHECK_BUFFER_FULL(ctx, length);
14566
14567 if(kmip_is_tag_next(ctx, KMIP_TAG_OPERATION))
14568 {
14569 result = kmip_decode_enum(ctx, KMIP_TAG_OPERATION, &value->operation);
14570 CHECK_RESULT(ctx, result);
14571 CHECK_ENUM(ctx, KMIP_TAG_OPERATION, value->operation);
14572 }
14573
14574 if(kmip_is_tag_next(ctx, KMIP_TAG_UNIQUE_BATCH_ITEM_ID))
14575 {
14576 value->unique_batch_item_id = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
14577 CHECK_NEW_MEMORY(ctx, value->unique_batch_item_id, sizeof(ByteString), "UniqueBatchItemID byte string");
14578
14579 result = kmip_decode_byte_string(ctx, KMIP_TAG_UNIQUE_BATCH_ITEM_ID, value->unique_batch_item_id);
14580 CHECK_RESULT(ctx, result);
14581 }
14582
14583 result = kmip_decode_enum(ctx, KMIP_TAG_RESULT_STATUS, &value->result_status);
14584 CHECK_RESULT(ctx, result);
14585 CHECK_ENUM(ctx, KMIP_TAG_RESULT_STATUS, value->result_status);
14586
14587 if(kmip_is_tag_next(ctx, KMIP_TAG_RESULT_REASON))
14588 {
14589 result = kmip_decode_enum(ctx, KMIP_TAG_RESULT_REASON, &value->result_reason);
14590 CHECK_RESULT(ctx, result);
14591 }
14592
14593 if(kmip_is_tag_next(ctx, KMIP_TAG_RESULT_MESSAGE))
14594 {
14595 value->result_message = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14596 CHECK_NEW_MEMORY(ctx, value->result_message, sizeof(TextString), "ResultMessage text string");
14597
14598 result = kmip_decode_text_string(ctx, KMIP_TAG_RESULT_MESSAGE, value->result_message);
14599 CHECK_RESULT(ctx, result);
14600 }
14601
14602 if(kmip_is_tag_next(ctx, KMIP_TAG_ASYNCHRONOUS_CORRELATION_VALUE))
14603 {
14604 value->asynchronous_correlation_value = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
14605 CHECK_NEW_MEMORY(ctx, value->asynchronous_correlation_value, sizeof(ByteString), "AsynchronousCorrelationValue byte string");
14606
14607 result = kmip_decode_byte_string(ctx, KMIP_TAG_ASYNCHRONOUS_CORRELATION_VALUE, value->asynchronous_correlation_value);
14608 CHECK_RESULT(ctx, result);
14609 }
14610
14611 /* NOTE (ph) Omitting the tag check is a good way to test error output. */
14612 //if(kmip_is_tag_next(ctx, KMIP_TAG_RESPONSE_PAYLOAD))
14613 {
14614 switch(value->operation)
14615 {
14616 case KMIP_OP_CREATE:
14617 value->response_payload = ctx->calloc_func(ctx->state, 1, sizeof(CreateResponsePayload));
14618 CHECK_NEW_MEMORY(ctx, value->response_payload, sizeof(CreateResponsePayload), "CreateResponsePayload structure");
14619 result = kmip_decode_create_response_payload(ctx, value->response_payload);
14620 break;
14621
14622 case KMIP_OP_REGISTER:
14623 value->response_payload = ctx->calloc_func(ctx->state, 1, sizeof(RegisterResponsePayload));
14624 CHECK_NEW_MEMORY(ctx, value->response_payload, sizeof(RegisterResponsePayload), "RegisterResponsePayload structure");
14625 result = kmip_decode_register_response_payload(ctx, value->response_payload);
14626 break;
14627
14628 case KMIP_OP_GET:
14629 value->response_payload = ctx->calloc_func(ctx->state, 1, sizeof(GetResponsePayload));
14630 CHECK_NEW_MEMORY(ctx, value->response_payload, sizeof(GetResponsePayload), "GetResponsePayload structure");
14631
14632 result = kmip_decode_get_response_payload(ctx, value->response_payload);
14633 break;
14634
14635 case KMIP_OP_GET_ATTRIBUTES:
14636 value->response_payload = ctx->calloc_func(ctx->state, 1, sizeof(GetAttributeResponsePayload));
14637 CHECK_NEW_MEMORY(ctx, value->response_payload, sizeof(GetAttributeResponsePayload), "GetAttributeResponsePayload structure");
14638
14639 result = kmip_decode_get_attribute_response_payload(ctx, value->response_payload);
14640 break;
14641
14642 case KMIP_OP_DESTROY:
14643 value->response_payload = ctx->calloc_func(ctx->state, 1, sizeof(DestroyResponsePayload));
14644 CHECK_NEW_MEMORY(ctx, value->response_payload, sizeof(DestroyResponsePayload), "DestroyResponsePayload structure");
14645 result = kmip_decode_destroy_response_payload(ctx, value->response_payload);
14646 break;
14647
14648 case KMIP_OP_QUERY:
14649 value->response_payload = ctx->calloc_func(ctx->state, 1, sizeof(QueryResponsePayload));
14650 CHECK_NEW_MEMORY(ctx, value->response_payload, sizeof(QueryResponsePayload), "QueryResponsePayload structure");
14651 result = kmip_decode_query_response_payload(ctx, value->response_payload);
14652 break;
14653
14654 case KMIP_OP_LOCATE:
14655 value->response_payload = ctx->calloc_func(ctx->state, 1, sizeof(LocateResponsePayload));
14656 CHECK_NEW_MEMORY(ctx, value->response_payload, sizeof(LocateResponsePayload), "LocateResponsePayload structure");
14657 result = kmip_decode_locate_response_payload(ctx, value->response_payload);
14658 break;
14659
14660 default:
14661 kmip_push_error_frame(ctx, __func__, __LINE__);
14662 return(KMIP_NOT_IMPLEMENTED);
14663 break;
14664 };
14665 CHECK_RESULT(ctx, result);
14666 }
14667
14668 return(KMIP_OK);
14669 }
14670
14671 int
14672 kmip_decode_nonce(KMIP *ctx, Nonce *value)
14673 {
14674 CHECK_BUFFER_FULL(ctx, 8);
14675
14676 int result = 0;
14677 int32 tag_type = 0;
14678 uint32 length = 0;
14679
14680 kmip_decode_int32_be(ctx, &tag_type);
14681 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_NONCE, KMIP_TYPE_STRUCTURE);
14682
14683 kmip_decode_length(ctx, &length);
14684 CHECK_BUFFER_FULL(ctx, length);
14685
14686 value->nonce_id = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
14687 CHECK_NEW_MEMORY(ctx, value->nonce_id, sizeof(ByteString), "NonceID byte string");
14688
14689 result = kmip_decode_byte_string(ctx, KMIP_TAG_NONCE_ID, value->nonce_id);
14690 CHECK_RESULT(ctx, result);
14691
14692 value->nonce_value = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
14693 CHECK_NEW_MEMORY(ctx, value->nonce_value, sizeof(ByteString), "NonceValue byte string");
14694
14695 result = kmip_decode_byte_string(ctx, KMIP_TAG_NONCE_VALUE, value->nonce_value);
14696 CHECK_RESULT(ctx, result);
14697
14698 return(KMIP_OK);
14699 }
14700
14701 int
14702 kmip_decode_username_password_credential(KMIP *ctx, UsernamePasswordCredential *value)
14703 {
14704 CHECK_BUFFER_FULL(ctx, 8);
14705
14706 int result = 0;
14707 int32 tag_type = 0;
14708 uint32 length = 0;
14709
14710 kmip_decode_int32_be(ctx, &tag_type);
14711 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_CREDENTIAL_VALUE, KMIP_TYPE_STRUCTURE);
14712
14713 kmip_decode_length(ctx, &length);
14714 CHECK_BUFFER_FULL(ctx, length);
14715
14716 value->username = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14717 CHECK_NEW_MEMORY(ctx, value->username, sizeof(TextString), "Username text string");
14718
14719 result = kmip_decode_text_string(ctx, KMIP_TAG_USERNAME, value->username);
14720 CHECK_RESULT(ctx, result);
14721
14722 if(kmip_is_tag_next(ctx, KMIP_TAG_PASSWORD))
14723 {
14724 value->password = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14725 CHECK_NEW_MEMORY(ctx, value->password, sizeof(TextString), "Password text string");
14726
14727 result = kmip_decode_text_string(ctx, KMIP_TAG_PASSWORD, value->password);
14728 CHECK_RESULT(ctx, result);
14729 }
14730
14731 return(KMIP_OK);
14732 }
14733
14734 int
14735 kmip_decode_device_credential(KMIP *ctx, DeviceCredential *value)
14736 {
14737 CHECK_BUFFER_FULL(ctx, 8);
14738
14739 int result = 0;
14740 int32 tag_type = 0;
14741 uint32 length = 0;
14742
14743 kmip_decode_int32_be(ctx, &tag_type);
14744 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_CREDENTIAL_VALUE, KMIP_TYPE_STRUCTURE);
14745
14746 kmip_decode_length(ctx, &length);
14747 CHECK_BUFFER_FULL(ctx, length);
14748
14749 if(kmip_is_tag_next(ctx, KMIP_TAG_DEVICE_SERIAL_NUMBER))
14750 {
14751 value->device_serial_number = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14752 CHECK_NEW_MEMORY(ctx, value->device_serial_number, sizeof(TextString), "DeviceSerialNumber text string");
14753
14754 result = kmip_decode_text_string(ctx, KMIP_TAG_DEVICE_SERIAL_NUMBER, value->device_serial_number);
14755 CHECK_RESULT(ctx, result);
14756 }
14757
14758 if(kmip_is_tag_next(ctx, KMIP_TAG_PASSWORD))
14759 {
14760 value->password = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14761 CHECK_NEW_MEMORY(ctx, value->password, sizeof(TextString), "Password text string");
14762
14763 result = kmip_decode_text_string(ctx, KMIP_TAG_PASSWORD, value->password);
14764 CHECK_RESULT(ctx, result);
14765 }
14766
14767 if(kmip_is_tag_next(ctx, KMIP_TAG_DEVICE_IDENTIFIER))
14768 {
14769 value->device_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14770 CHECK_NEW_MEMORY(ctx, value->device_identifier, sizeof(TextString), "DeviceIdentifier text string");
14771
14772 result = kmip_decode_text_string(ctx, KMIP_TAG_DEVICE_IDENTIFIER, value->device_identifier);
14773 CHECK_RESULT(ctx, result);
14774 }
14775
14776 if(kmip_is_tag_next(ctx, KMIP_TAG_NETWORK_IDENTIFIER))
14777 {
14778 value->network_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14779 CHECK_NEW_MEMORY(ctx, value->network_identifier, sizeof(TextString), "NetworkIdentifier text string");
14780
14781 result = kmip_decode_text_string(ctx, KMIP_TAG_NETWORK_IDENTIFIER, value->network_identifier);
14782 CHECK_RESULT(ctx, result);
14783 }
14784
14785 if(kmip_is_tag_next(ctx, KMIP_TAG_MACHINE_IDENTIFIER))
14786 {
14787 value->machine_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14788 CHECK_NEW_MEMORY(ctx, value->machine_identifier, sizeof(TextString), "MachineIdentifier text string");
14789
14790 result = kmip_decode_text_string(ctx, KMIP_TAG_MACHINE_IDENTIFIER, value->machine_identifier);
14791 CHECK_RESULT(ctx, result);
14792 }
14793
14794 if(kmip_is_tag_next(ctx, KMIP_TAG_MEDIA_IDENTIFIER))
14795 {
14796 value->media_identifier = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14797 CHECK_NEW_MEMORY(ctx, value->media_identifier, sizeof(TextString), "MediaIdentifier text string");
14798
14799 result = kmip_decode_text_string(ctx, KMIP_TAG_MEDIA_IDENTIFIER, value->media_identifier);
14800 CHECK_RESULT(ctx, result);
14801 }
14802
14803 return(KMIP_OK);
14804 }
14805
14806 int
14807 kmip_decode_attestation_credential(KMIP *ctx, AttestationCredential *value)
14808 {
14809 CHECK_BUFFER_FULL(ctx, 8);
14810
14811 int result = 0;
14812 int32 tag_type = 0;
14813 uint32 length = 0;
14814
14815 kmip_decode_int32_be(ctx, &tag_type);
14816 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_CREDENTIAL_VALUE, KMIP_TYPE_STRUCTURE);
14817
14818 kmip_decode_length(ctx, &length);
14819 CHECK_BUFFER_FULL(ctx, length);
14820
14821 value->nonce = ctx->calloc_func(ctx->state, 1, sizeof(Nonce));
14822 CHECK_NEW_MEMORY(ctx, value->nonce, sizeof(Nonce), "Nonce structure");
14823
14824 result = kmip_decode_nonce(ctx, value->nonce);
14825 CHECK_RESULT(ctx, result);
14826
14827 result = kmip_decode_enum(ctx, KMIP_TAG_ATTESTATION_TYPE, &value->attestation_type);
14828 CHECK_RESULT(ctx, result);
14829 CHECK_ENUM(ctx, KMIP_TAG_ATTESTATION_TYPE, value->attestation_type);
14830
14831 if(kmip_is_tag_next(ctx, KMIP_TAG_ATTESTATION_MEASUREMENT))
14832 {
14833 value->attestation_measurement = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
14834 CHECK_NEW_MEMORY(ctx, value->attestation_measurement, sizeof(ByteString), "AttestationMeasurement byte string");
14835
14836 result = kmip_decode_byte_string(ctx, KMIP_TAG_ATTESTATION_MEASUREMENT, value->attestation_measurement);
14837 CHECK_RESULT(ctx, result);
14838 }
14839
14840 if(kmip_is_tag_next(ctx, KMIP_TAG_ATTESTATION_ASSERTION))
14841 {
14842 value->attestation_assertion = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
14843 CHECK_NEW_MEMORY(ctx, value->attestation_assertion, sizeof(ByteString), "AttestationAssertion byte string");
14844
14845 result = kmip_decode_byte_string(ctx, KMIP_TAG_ATTESTATION_ASSERTION, value->attestation_assertion);
14846 CHECK_RESULT(ctx, result);
14847 }
14848
14849 return(KMIP_OK);
14850 }
14851
14852 int
14853 kmip_decode_credential_value(KMIP *ctx, enum credential_type type, void **value)
14854 {
14855 int result = 0;
14856
14857 switch(type)
14858 {
14859 case KMIP_CRED_USERNAME_AND_PASSWORD:
14860 *value = ctx->calloc_func(ctx->state, 1, sizeof(UsernamePasswordCredential));
14861 CHECK_NEW_MEMORY(ctx, *value, sizeof(UsernamePasswordCredential), "UsernamePasswordCredential structure");
14862 result = kmip_decode_username_password_credential(ctx, (UsernamePasswordCredential *)*value);
14863 break;
14864
14865 case KMIP_CRED_DEVICE:
14866 *value = ctx->calloc_func(ctx->state, 1, sizeof(DeviceCredential));
14867 CHECK_NEW_MEMORY(ctx, *value, sizeof(DeviceCredential), "DeviceCredential structure");
14868 result = kmip_decode_device_credential(ctx, (DeviceCredential *)*value);
14869 break;
14870
14871 case KMIP_CRED_ATTESTATION:
14872 *value = ctx->calloc_func(ctx->state, 1, sizeof(AttestationCredential));
14873 CHECK_NEW_MEMORY(ctx, *value, sizeof(AttestationCredential), "AttestationCredential structure");
14874 result = kmip_decode_attestation_credential(ctx, (AttestationCredential*)*value);
14875 break;
14876
14877 default:
14878 kmip_push_error_frame(ctx, __func__, __LINE__);
14879 return(KMIP_NOT_IMPLEMENTED);
14880 break;
14881 }
14882 CHECK_RESULT(ctx, result);
14883
14884 return(KMIP_OK);
14885 }
14886
14887 int
14888 kmip_decode_credential(KMIP *ctx, Credential *value)
14889 {
14890 CHECK_BUFFER_FULL(ctx, 8);
14891
14892 int result = 0;
14893 int32 tag_type = 0;
14894 uint32 length = 0;
14895
14896 kmip_decode_int32_be(ctx, &tag_type);
14897 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_CREDENTIAL, KMIP_TYPE_STRUCTURE);
14898
14899 kmip_decode_length(ctx, &length);
14900 CHECK_BUFFER_FULL(ctx, length);
14901
14902 result = kmip_decode_enum(ctx, KMIP_TAG_CREDENTIAL_TYPE, &value->credential_type);
14903 CHECK_RESULT(ctx, result);
14904 CHECK_ENUM(ctx, KMIP_TAG_CREDENTIAL_TYPE, value->credential_type);
14905
14906 result = kmip_decode_credential_value(ctx, value->credential_type, &value->credential_value);
14907 CHECK_RESULT(ctx, result);
14908
14909 return(KMIP_OK);
14910 }
14911
14912 int
14913 kmip_decode_authentication(KMIP *ctx, Authentication *value)
14914 {
14915 CHECK_BUFFER_FULL(ctx, 8);
14916
14917 int result = 0;
14918 int32 tag_type = 0;
14919 uint32 length = 0;
14920
14921 kmip_decode_int32_be(ctx, &tag_type);
14922 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_AUTHENTICATION, KMIP_TYPE_STRUCTURE);
14923
14924 kmip_decode_length(ctx, &length);
14925 CHECK_BUFFER_FULL(ctx, length);
14926
14927 value->credential = ctx->calloc_func(ctx->state, 1, sizeof(Credential));
14928 CHECK_NEW_MEMORY(ctx, value->credential, sizeof(Credential), "Credential structure");
14929
14930 result = kmip_decode_credential(ctx, value->credential);
14931 CHECK_RESULT(ctx, result);
14932
14933 return(KMIP_OK);
14934 }
14935
14936 int
14937 kmip_decode_request_header(KMIP *ctx, RequestHeader *value)
14938 {
14939 CHECK_BUFFER_FULL(ctx, 8);
14940
14941 int result = 0;
14942 int32 tag_type = 0;
14943 uint32 length = 0;
14944
14945 kmip_decode_int32_be(ctx, &tag_type);
14946 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_REQUEST_HEADER, KMIP_TYPE_STRUCTURE);
14947
14948 kmip_decode_length(ctx, &length);
14949 CHECK_BUFFER_FULL(ctx, length);
14950
14951 value->protocol_version = ctx->calloc_func(ctx->state, 1, sizeof(ProtocolVersion));
14952 CHECK_NEW_MEMORY(ctx, value->protocol_version, sizeof(ProtocolVersion), "ProtocolVersion structure");
14953
14954 result = kmip_decode_protocol_version(ctx, value->protocol_version);
14955 CHECK_RESULT(ctx, result);
14956
14957 if(kmip_is_tag_next(ctx, KMIP_TAG_MAXIMUM_RESPONSE_SIZE))
14958 {
14959 result = kmip_decode_integer(ctx, KMIP_TAG_MAXIMUM_RESPONSE_SIZE, &value->maximum_response_size);
14960 CHECK_RESULT(ctx, result);
14961 }
14962
14963 if(ctx->version >= KMIP_1_4)
14964 {
14965 if(kmip_is_tag_next(ctx, KMIP_TAG_CLIENT_CORRELATION_VALUE))
14966 {
14967 value->client_correlation_value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14968 CHECK_NEW_MEMORY(ctx, value->client_correlation_value, sizeof(TextString), "ClientCorrelationValue text string");
14969
14970 result = kmip_decode_text_string(ctx, KMIP_TAG_CLIENT_CORRELATION_VALUE, value->client_correlation_value);
14971 CHECK_RESULT(ctx, result);
14972 }
14973
14974 if(kmip_is_tag_next(ctx, KMIP_TAG_SERVER_CORRELATION_VALUE))
14975 {
14976 value->server_correlation_value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
14977 CHECK_NEW_MEMORY(ctx, value->server_correlation_value, sizeof(TextString), "ServerCorrelationValue text string");
14978
14979 result = kmip_decode_text_string(ctx, KMIP_TAG_SERVER_CORRELATION_VALUE, value->server_correlation_value);
14980 CHECK_RESULT(ctx, result);
14981 }
14982 }
14983
14984 if(kmip_is_tag_next(ctx, KMIP_TAG_ASYNCHRONOUS_INDICATOR))
14985 {
14986 result = kmip_decode_bool(ctx, KMIP_TAG_ASYNCHRONOUS_INDICATOR, &value->asynchronous_indicator);
14987 CHECK_RESULT(ctx, result);
14988 }
14989
14990 if(ctx->version >= KMIP_1_2)
14991 {
14992 if(kmip_is_tag_next(ctx, KMIP_TAG_ATTESTATION_CAPABLE_INDICATOR))
14993 {
14994 result = kmip_decode_bool(ctx, KMIP_TAG_ATTESTATION_CAPABLE_INDICATOR, &value->attestation_capable_indicator);
14995 CHECK_RESULT(ctx, result);
14996 }
14997
14998 value->attestation_type_count = kmip_get_num_items_next(ctx, KMIP_TAG_ATTESTATION_TYPE);
14999 if(value->attestation_type_count > 0)
15000 {
15001 value->attestation_types = ctx->calloc_func(ctx->state, value->attestation_type_count, sizeof(enum attestation_type));
15002 CHECK_NEW_MEMORY(ctx, value->attestation_types, value->attestation_type_count * sizeof(enum attestation_type), "sequence of AttestationType enumerations");
15003
15004 for(size_t i = 0; i < value->attestation_type_count; i++)
15005 {
15006 result = kmip_decode_enum(ctx, KMIP_TAG_ATTESTATION_TYPE, &value->attestation_types[i]);
15007 CHECK_RESULT(ctx, result);
15008 CHECK_ENUM(ctx, KMIP_TAG_ATTESTATION_TYPE, value->attestation_types[i]);
15009 }
15010 }
15011 }
15012
15013 if(kmip_is_tag_next(ctx, KMIP_TAG_AUTHENTICATION))
15014 {
15015 value->authentication = ctx->calloc_func(ctx->state,1, sizeof(Authentication));
15016 CHECK_NEW_MEMORY(ctx, value->authentication, sizeof(Authentication), "Authentication structure");
15017
15018 result = kmip_decode_authentication(ctx, value->authentication);
15019 CHECK_RESULT(ctx, result);
15020 }
15021
15022 if(kmip_is_tag_next(ctx, KMIP_TAG_BATCH_ERROR_CONTINUATION_OPTION))
15023 {
15024 result = kmip_decode_enum(ctx, KMIP_TAG_BATCH_ERROR_CONTINUATION_OPTION, &value->batch_error_continuation_option);
15025 CHECK_RESULT(ctx, result);
15026 CHECK_ENUM(ctx, KMIP_TAG_BATCH_ERROR_CONTINUATION_OPTION, value->batch_error_continuation_option);
15027 }
15028
15029 if(kmip_is_tag_next(ctx, KMIP_TAG_BATCH_ORDER_OPTION))
15030 {
15031 result = kmip_decode_bool(ctx, KMIP_TAG_BATCH_ORDER_OPTION, &value->batch_order_option);
15032 CHECK_RESULT(ctx, result);
15033 }
15034
15035 if(kmip_is_tag_next(ctx, KMIP_TAG_TIME_STAMP))
15036 {
15037 result = kmip_decode_date_time(ctx, KMIP_TAG_TIME_STAMP, &value->time_stamp);
15038 CHECK_RESULT(ctx, result);
15039 }
15040
15041 result = kmip_decode_integer(ctx, KMIP_TAG_BATCH_COUNT, &value->batch_count);
15042 CHECK_RESULT(ctx, result);
15043
15044 return(KMIP_OK);
15045 }
15046
15047 int
15048 kmip_decode_response_header(KMIP *ctx, ResponseHeader *value)
15049 {
15050 CHECK_BUFFER_FULL(ctx, 8);
15051
15052 int result = 0;
15053 int32 tag_type = 0;
15054 uint32 length = 0;
15055
15056 kmip_decode_int32_be(ctx, &tag_type);
15057 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_RESPONSE_HEADER, KMIP_TYPE_STRUCTURE);
15058
15059 kmip_decode_length(ctx, &length);
15060 CHECK_BUFFER_FULL(ctx, length);
15061
15062 value->protocol_version = ctx->calloc_func(ctx->state, 1, sizeof(ProtocolVersion));
15063 CHECK_NEW_MEMORY(ctx, value->protocol_version, sizeof(ProtocolVersion), "ProtocolVersion structure");
15064
15065 result = kmip_decode_protocol_version(ctx, value->protocol_version);
15066 CHECK_RESULT(ctx, result);
15067
15068 result = kmip_decode_date_time(ctx, KMIP_TAG_TIME_STAMP, &value->time_stamp);
15069 CHECK_RESULT(ctx, result);
15070
15071 if(ctx->version >= KMIP_1_2)
15072 {
15073 if(kmip_is_tag_next(ctx, KMIP_TAG_NONCE))
15074 {
15075 value->nonce = ctx->calloc_func(ctx->state, 1, sizeof(Nonce));
15076 CHECK_NEW_MEMORY(ctx, value->nonce, sizeof(Nonce), "Nonce structure");
15077
15078 result = kmip_decode_nonce(ctx, value->nonce);
15079 CHECK_RESULT(ctx, result);
15080 }
15081
15082 if(ctx->version >= KMIP_2_0)
15083 {
15084 if(kmip_is_tag_next(ctx, KMIP_TAG_SERVER_HASHED_PASSWORD))
15085 {
15086 value->server_hashed_password = ctx->calloc_func(ctx->state, 1, sizeof(ByteString));
15087 CHECK_NEW_MEMORY(ctx, value->server_hashed_password, sizeof(ByteString), "ByteString");
15088
15089 result = kmip_decode_byte_string(ctx, KMIP_TAG_SERVER_HASHED_PASSWORD, value->server_hashed_password);
15090 CHECK_RESULT(ctx, result);
15091 }
15092 }
15093
15094 value->attestation_type_count = kmip_get_num_items_next(ctx, KMIP_TAG_ATTESTATION_TYPE);
15095 if(value->attestation_type_count > 0)
15096 {
15097 value->attestation_types = ctx->calloc_func(ctx->state, value->attestation_type_count, sizeof(enum attestation_type));
15098 CHECK_NEW_MEMORY(ctx, value->attestation_types, value->attestation_type_count * sizeof(enum attestation_type), "sequence of AttestationType enumerations");
15099
15100 for(size_t i = 0; i < value->attestation_type_count; i++)
15101 {
15102 result = kmip_decode_enum(ctx, KMIP_TAG_ATTESTATION_TYPE, &value->attestation_types[i]);
15103 CHECK_RESULT(ctx, result);
15104 CHECK_ENUM(ctx, KMIP_TAG_ATTESTATION_TYPE, value->attestation_types[i]);
15105 }
15106 }
15107 }
15108
15109 if(ctx->version >= KMIP_1_4)
15110 {
15111 if(kmip_is_tag_next(ctx, KMIP_TAG_CLIENT_CORRELATION_VALUE))
15112 {
15113 value->client_correlation_value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15114 CHECK_NEW_MEMORY(ctx, value->client_correlation_value, sizeof(TextString), "ClientCorrelationValue text string");
15115
15116 result = kmip_decode_text_string(ctx, KMIP_TAG_CLIENT_CORRELATION_VALUE, value->client_correlation_value);
15117 CHECK_RESULT(ctx, result);
15118 }
15119
15120 if(kmip_is_tag_next(ctx, KMIP_TAG_SERVER_CORRELATION_VALUE))
15121 {
15122 value->server_correlation_value = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15123 CHECK_NEW_MEMORY(ctx, value->server_correlation_value, sizeof(TextString), "ServerCorrelationValue text string");
15124
15125 result = kmip_decode_text_string(ctx, KMIP_TAG_SERVER_CORRELATION_VALUE, value->server_correlation_value);
15126 CHECK_RESULT(ctx, result);
15127 }
15128 }
15129
15130 result = kmip_decode_integer(ctx, KMIP_TAG_BATCH_COUNT, &value->batch_count);
15131 CHECK_RESULT(ctx, result);
15132
15133 return(KMIP_OK);
15134 }
15135
15136 int
15137 kmip_decode_request_message(KMIP *ctx, RequestMessage *value)
15138 {
15139 CHECK_BUFFER_FULL(ctx, 8);
15140
15141 int result = 0;
15142 int32 tag_type = 0;
15143 uint32 length = 0;
15144
15145 kmip_decode_int32_be(ctx, &tag_type);
15146 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_REQUEST_MESSAGE, KMIP_TYPE_STRUCTURE);
15147
15148 kmip_decode_length(ctx, &length);
15149 CHECK_BUFFER_FULL(ctx, length);
15150
15151 value->request_header = ctx->calloc_func(ctx->state, 1, sizeof(RequestHeader));
15152 CHECK_NEW_MEMORY(ctx, value->request_header, sizeof(RequestHeader), "RequestHeader structure");
15153 kmip_init_request_header(value->request_header);
15154 result = kmip_decode_request_header(ctx, value->request_header);
15155 CHECK_RESULT(ctx, result);
15156
15157 value->batch_count = kmip_get_num_items_next(ctx, KMIP_TAG_BATCH_ITEM);
15158 if(value->batch_count > 0)
15159 {
15160 value->batch_items = ctx->calloc_func(ctx->state, value->batch_count, sizeof(RequestBatchItem));
15161 CHECK_NEW_MEMORY(ctx, value->batch_items, value->batch_count * sizeof(RequestBatchItem), "sequence of RequestBatchItem structures");
15162
15163 for(size_t i = 0; i < value->batch_count; i++)
15164 {
15165 kmip_init_request_batch_item(&value->batch_items[i]);
15166 result = kmip_decode_request_batch_item(ctx, &value->batch_items[i]);
15167 CHECK_RESULT(ctx, result);
15168 }
15169 }
15170
15171 return(KMIP_OK);
15172 }
15173
15174 int
15175 kmip_decode_response_message(KMIP *ctx, ResponseMessage *value)
15176 {
15177 CHECK_BUFFER_FULL(ctx, 8);
15178
15179 int result = 0;
15180 int32 tag_type = 0;
15181 uint32 length = 0;
15182
15183 kmip_decode_int32_be(ctx, &tag_type);
15184 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_RESPONSE_MESSAGE, KMIP_TYPE_STRUCTURE);
15185
15186 kmip_decode_length(ctx, &length);
15187 CHECK_BUFFER_FULL(ctx, length);
15188
15189 value->response_header = ctx->calloc_func(ctx->state, 1, sizeof(ResponseHeader));
15190 CHECK_NEW_MEMORY(ctx, value->response_header, sizeof(ResponseHeader), "ResponseHeader structure");
15191
15192 result = kmip_decode_response_header(ctx, value->response_header);
15193 CHECK_RESULT(ctx, result);
15194
15195 value->batch_count = kmip_get_num_items_next(ctx, KMIP_TAG_BATCH_ITEM);
15196 if(value->batch_count > 0)
15197 {
15198 value->batch_items = ctx->calloc_func(ctx->state, value->batch_count, sizeof(ResponseBatchItem));
15199 CHECK_NEW_MEMORY(ctx, value->batch_items, value->batch_count * sizeof(ResponseBatchItem), "sequence of ResponseBatchItem structures");
15200
15201 for(size_t i = 0; i < value->batch_count; i++)
15202 {
15203 result = kmip_decode_response_batch_item(ctx, &value->batch_items[i]);
15204 CHECK_RESULT(ctx, result);
15205 }
15206 }
15207
15208 return(KMIP_OK);
15209 }
15210
15211 int
15212 kmip_decode_query_functions(KMIP *ctx, Functions* value)
15213 {
15214 int result = 0;
15215 uint32 tag = kmip_peek_tag(ctx);
15216
15217 value->function_list = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
15218 CHECK_NEW_MEMORY(ctx, value->function_list, sizeof(LinkedList), "LinkedList");
15219
15220 while(tag == KMIP_TAG_QUERY_FUNCTION)
15221 {
15222 LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
15223 CHECK_NEW_MEMORY(ctx, item, sizeof(LinkedListItem), "LinkedListItem");
15224 kmip_linked_list_enqueue(value->function_list, item);
15225
15226 item->data = ctx->calloc_func(ctx->state, 1, sizeof(int32));
15227 CHECK_NEW_MEMORY(ctx, item->data, sizeof(int32), "Query Function");
15228
15229 result = kmip_decode_enum(ctx, KMIP_TAG_QUERY_FUNCTION, (int32 *)item->data);
15230 CHECK_RESULT(ctx, result);
15231
15232 tag = kmip_peek_tag(ctx);
15233 }
15234
15235 return(KMIP_OK);
15236 }
15237
15238 int
15239 kmip_decode_query_request_payload(KMIP *ctx, QueryRequestPayload *value)
15240 {
15241 CHECK_DECODE_ARGS(ctx, value);
15242 CHECK_BUFFER_FULL(ctx, 8);
15243
15244 int result = 0;
15245 int32 tag_type = 0;
15246 uint32 length = 0;
15247
15248 result = kmip_decode_int32_be(ctx, &tag_type);
15249 CHECK_RESULT(ctx, result);
15250 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_QUERY_FUNCTION, KMIP_TYPE_STRUCTURE);
15251
15252 result = kmip_decode_int32_be(ctx, &length);
15253 CHECK_RESULT(ctx, result);
15254 CHECK_BUFFER_FULL(ctx, length);
15255
15256 if(kmip_is_tag_next(ctx, KMIP_TAG_QUERY_FUNCTION))
15257 {
15258 value->functions = ctx->calloc_func(ctx->state, 1, sizeof(Functions));
15259 CHECK_NEW_MEMORY(ctx, value->functions, sizeof(Functions), "Functions");
15260
15261 result = kmip_decode_query_functions(ctx, value->functions);
15262 CHECK_RESULT(ctx, result);
15263 }
15264
15265 return(KMIP_OK);
15266 }
15267
15268
15269 int
15270 kmip_decode_operations(KMIP *ctx, Operations *value)
15271 {
15272 int result = 0;
15273
15274 value->operation_list = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
15275 CHECK_NEW_MEMORY(ctx, value->operation_list, sizeof(LinkedList), "LinkedList");
15276
15277 uint32 tag = kmip_peek_tag(ctx);
15278 while(tag == KMIP_TAG_OPERATION)
15279 {
15280 LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
15281 CHECK_NEW_MEMORY(ctx, item, sizeof(LinkedListItem), "LinkedListItem");
15282 kmip_linked_list_enqueue(value->operation_list, item);
15283
15284 item->data = ctx->calloc_func(ctx->state, 1, sizeof(int32));
15285 CHECK_NEW_MEMORY(ctx, item->data, sizeof(int32), "Operation");
15286
15287
15288 result = kmip_decode_enum(ctx, KMIP_TAG_OPERATION, (int32 *)item->data);
15289 CHECK_RESULT(ctx, result);
15290
15291 tag = kmip_peek_tag(ctx);
15292 }
15293
15294 return(KMIP_OK);
15295 }
15296
15297 int
15298 kmip_decode_object_types(KMIP *ctx, ObjectTypes *value)
15299 {
15300 int result = 0;
15301
15302 value->object_list = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
15303 CHECK_NEW_MEMORY(ctx, value->object_list, sizeof(LinkedList), "LinkedList");
15304
15305 uint32 tag = kmip_peek_tag(ctx);
15306 while(tag == KMIP_TAG_OBJECT_TYPE)
15307 {
15308 LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
15309 CHECK_NEW_MEMORY(ctx, item, sizeof(LinkedListItem), "LinkedListItem");
15310 kmip_linked_list_enqueue(value->object_list, item);
15311
15312 item->data = ctx->calloc_func(ctx->state, 1, sizeof(int32));
15313 CHECK_NEW_MEMORY(ctx, item->data, sizeof(int32), "Object");
15314
15315 result = kmip_decode_enum(ctx, KMIP_TAG_OBJECT_TYPE, (int32 *)item->data);
15316 CHECK_RESULT(ctx, result);
15317
15318 tag = kmip_peek_tag(ctx);
15319 }
15320
15321 return(KMIP_OK);
15322 }
15323
15324 int
15325 kmip_decode_alternative_endpoints(KMIP *ctx, AltEndpoints* value)
15326 {
15327 int result = 0;
15328
15329 value->endpoint_list = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
15330 CHECK_NEW_MEMORY(ctx, value->endpoint_list, sizeof(LinkedList), "LinkedList");
15331
15332 uint32 tag = kmip_peek_tag(ctx);
15333 while(tag == KMIP_TAG_ALTERNATE_FAILOVER_ENDPOINTS)
15334 {
15335 LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
15336 CHECK_NEW_MEMORY(ctx, item, sizeof(LinkedListItem), "LinkedListItem");
15337 kmip_linked_list_enqueue(value->endpoint_list, item);
15338
15339 item->data = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15340 CHECK_NEW_MEMORY(ctx, item->data, sizeof(TextString), "Endpoint text string");
15341
15342 result = kmip_decode_text_string(ctx, KMIP_TAG_ALTERNATE_FAILOVER_ENDPOINTS, item->data);
15343 CHECK_RESULT(ctx, result);
15344
15345 tag = kmip_peek_tag(ctx);
15346 }
15347
15348 return(KMIP_OK);
15349 }
15350
15351 int
15352 kmip_decode_server_information(KMIP *ctx, ServerInformation *value)
15353 {
15354 CHECK_BUFFER_FULL(ctx, 8);
15355
15356 int result = 0;
15357 int32 tag_type = 0;
15358 uint32 length = 0;
15359
15360 kmip_decode_int32_be(ctx, &tag_type);
15361 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_SERVER_INFORMATION, KMIP_TYPE_STRUCTURE);
15362
15363 kmip_decode_int32_be(ctx, &length);
15364 CHECK_BUFFER_FULL(ctx, length);
15365
15366 if(kmip_is_tag_next(ctx, KMIP_TAG_SERVER_NAME))
15367 {
15368 value->server_name = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15369 CHECK_NEW_MEMORY(ctx, value->server_name, sizeof(TextString), "ServerName text string");
15370
15371 result = kmip_decode_text_string(ctx, KMIP_TAG_SERVER_NAME, value->server_name);
15372 CHECK_RESULT(ctx, result);
15373 }
15374
15375 if(kmip_is_tag_next(ctx, KMIP_TAG_SERVER_SERIAL_NUMBER))
15376 {
15377 value->server_serial_number = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15378 CHECK_NEW_MEMORY(ctx, value->server_serial_number, sizeof(TextString), "ServerSerialNumber text string");
15379
15380 result = kmip_decode_text_string(ctx, KMIP_TAG_SERVER_SERIAL_NUMBER, value->server_serial_number);
15381 CHECK_RESULT(ctx, result);
15382 }
15383
15384 if(kmip_is_tag_next(ctx, KMIP_TAG_SERVER_VERSION))
15385 {
15386 value->server_version = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15387 CHECK_NEW_MEMORY(ctx, value->server_version, sizeof(TextString), "ServerVersion text string");
15388
15389 result = kmip_decode_text_string(ctx, KMIP_TAG_SERVER_VERSION, value->server_version);
15390 CHECK_RESULT(ctx, result);
15391 }
15392
15393 if(kmip_is_tag_next(ctx, KMIP_TAG_SERVER_LOAD))
15394 {
15395 value->server_load = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15396 CHECK_NEW_MEMORY(ctx, value->server_load, sizeof(TextString), "ServerLoad text string");
15397
15398 result = kmip_decode_text_string(ctx, KMIP_TAG_SERVER_LOAD, value->server_load);
15399 CHECK_RESULT(ctx, result);
15400 }
15401
15402
15403 if(kmip_is_tag_next(ctx, KMIP_TAG_PRODUCT_NAME))
15404 {
15405 value->product_name = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15406 CHECK_NEW_MEMORY(ctx, value->product_name, sizeof(TextString), "ProductName text string");
15407
15408 result = kmip_decode_text_string(ctx, KMIP_TAG_PRODUCT_NAME, value->product_name);
15409 CHECK_RESULT(ctx, result);
15410 }
15411
15412 if(kmip_is_tag_next(ctx, KMIP_TAG_BUILD_LEVEL))
15413 {
15414 value->build_level = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15415 CHECK_NEW_MEMORY(ctx, value->build_level, sizeof(TextString), "BuildLevel text string");
15416
15417 result = kmip_decode_text_string(ctx, KMIP_TAG_BUILD_LEVEL, value->build_level);
15418 CHECK_RESULT(ctx, result);
15419 }
15420
15421 if(kmip_is_tag_next(ctx, KMIP_TAG_BUILD_DATE))
15422 {
15423 value->build_date = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15424 CHECK_NEW_MEMORY(ctx, value->build_date, sizeof(TextString), "BuildDate text string");
15425
15426 result = kmip_decode_text_string(ctx, KMIP_TAG_BUILD_DATE, value->build_date);
15427 CHECK_RESULT(ctx, result);
15428 }
15429
15430 if(kmip_is_tag_next(ctx, KMIP_TAG_CLUSTER_INFO))
15431 {
15432 value->cluster_info = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15433 CHECK_NEW_MEMORY(ctx, value->cluster_info, sizeof(TextString), "ClusterInfo text string");
15434
15435 result = kmip_decode_text_string(ctx, KMIP_TAG_CLUSTER_INFO, value->cluster_info);
15436 CHECK_RESULT(ctx, result);
15437 }
15438
15439 if(kmip_is_tag_next(ctx, KMIP_TAG_ALTERNATE_FAILOVER_ENDPOINTS))
15440 {
15441 value->alternative_failover_endpoints= ctx->calloc_func(ctx->state, 1, sizeof(AltEndpoints));
15442 CHECK_NEW_MEMORY(ctx, value->alternative_failover_endpoints, sizeof(AltEndpoints), "Alt Endpoints");
15443 result = kmip_decode_alternative_endpoints(ctx, value->alternative_failover_endpoints);
15444 CHECK_RESULT(ctx, result);
15445 }
15446
15447 return(KMIP_OK);
15448 }
15449
15450 int
15451 kmip_decode_query_response_payload(KMIP *ctx, QueryResponsePayload *value)
15452 {
15453 int result = 0;
15454
15455 int32 tag_type = 0;
15456 uint32 length = 0;
15457
15458 kmip_decode_int32_be(ctx, &tag_type);
15459 CHECK_TAG_TYPE(ctx, tag_type, KMIP_TAG_RESPONSE_PAYLOAD, KMIP_TYPE_STRUCTURE);
15460
15461 kmip_decode_int32_be(ctx, &length);
15462 CHECK_BUFFER_FULL(ctx, length);
15463
15464 if(kmip_is_tag_next(ctx, KMIP_TAG_OPERATION))
15465 {
15466 value->operations = ctx->calloc_func(ctx->state, 1, sizeof(Operations));
15467 CHECK_NEW_MEMORY(ctx, value->operations, sizeof(Operations), "Operations");
15468 result = kmip_decode_operations(ctx, value->operations);
15469 CHECK_RESULT(ctx, result);
15470 }
15471
15472 if(kmip_is_tag_next(ctx, KMIP_TAG_OBJECT_TYPE))
15473 {
15474 value->objects = ctx->calloc_func(ctx->state, 1, sizeof(ObjectTypes));
15475 CHECK_NEW_MEMORY(ctx, value->objects, sizeof(ObjectTypes), "Object_Types");
15476 result = kmip_decode_object_types(ctx, value->objects);
15477 CHECK_RESULT(ctx, result);
15478 }
15479
15480 if(kmip_is_tag_next(ctx, KMIP_TAG_VENDOR_IDENTIFICATION))
15481 {
15482 value->vendor_identification = ctx->calloc_func(ctx->state, 1, sizeof(TextString));
15483 CHECK_NEW_MEMORY(ctx, value->vendor_identification, sizeof(TextString), "Vendor Identifier text string");
15484 result = kmip_decode_text_string(ctx, KMIP_TAG_VENDOR_IDENTIFICATION, (TextString*)value->vendor_identification);
15485 CHECK_RESULT(ctx, result);
15486 }
15487
15488 if(kmip_is_tag_next(ctx, KMIP_TAG_SERVER_INFORMATION))
15489 {
15490 value->server_information = ctx->calloc_func(ctx->state, 1, sizeof(ServerInformation));
15491 CHECK_NEW_MEMORY(ctx, value->server_information, sizeof(ServerInformation), "Server Information");
15492 result = kmip_decode_server_information(ctx, value->server_information);
15493 CHECK_RESULT(ctx, result);
15494 }
15495
15496 return(KMIP_OK);
15497 }
15498
15499